简体   繁体   中英

what does the token ! mean in this context (alongside a binding)?

I guess this mean no something but I'm not sure and besides I don't get what does it mean in the loop context

This a function looping through an array of objects.

function journalEvents(journal) {
let events = [];
   for (let entry of journal) {
     for (let event of entry.events) {
       if (!events.includes(event)) {
         events.push(event);
       }
} }
   return events;
 }

I outputs 4 numbers, getting a pattern in the data

This is a logical "not" operator.

It basically means "take the opposite of this boolean". When the boolean after it is true, it returns false, and vise versa.

In your context, the if statement there means "if event isn't in events". This prevents the code from adding the same event to the "events" array twice.

You can read more on logical operators here !

includes is a boolean function: it return true weather the element event does exist in events list. The ! operator juust reverse the returning value (ie you get false if it returns true, and true otherwise).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM