Tag Archives: some

JavaScript30—Day 7

JavaScript30 is 30-day vanilla javaScript coding challenge by Wes Bos (@wesbos). The purpose of these posts is to reflect my troubles and moments of ahhaa. Lessons from Day 7 — Array Cardio 2: Demo - Day 7
  1. Array.prototype.some(); is there at least one match? Returns true or false.
  2. Array.prototype.every(); every single item in array matches to the condition or not? Returns true or false.
  3. console.log({variable}); - in console can be seen like
    
    isAdult:true
    
  4. Array.prototype.find(); Find is like filter, but instead returns just the one you are looking for
  5. With all these methods we can use array method without if-statment— because method returns true or false. So, instead this:
    const comment = comments.find(function(comment){
          if (comment.id === 823423){
             return true;
          }
    
        });
    
    we can write:
    const comment = comments.find(comment => comment.id ===823423);
    
  6. Deleting from array: First use Array.prototype.findIndex() and then use splice()
     const commentB = comments.findIndex(comment=>comment.id ===823423);
     //returns 1
    comments.splice(0, 1);
    
    or creating new array, spread and slice(),
    const index = comments.findIndex(comment=>comment.id ===542328);
        const newComments = [
          ...comments.slice(0,index),
          ...comments.slice(index + 1)
        ];
        console.table(newComments);
    
Day 7 code on github.