Tag Archives: array

JavaScript30—Day 3

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 3 — CSS Variables + JS: Demo - Day 3
  1. - - declares variables in CSS as $ in php or var in javaScript. You declare:
    :root{
    --basecolor:#ffc600;
    }
    
    
    and call it out like this:
    p {
     backround-color: var(--basecolor);
    }
    
  2. :root is the deepest level you can go.
  3. If you want update your e.g. style attribute according to input via javaScript variable and name should have the same name, otherwise it wont work:
    
    
    - -basecolor:#ffc600;
  4. NodeList vs array document.querySelectorAll gives NodeList. The difference between NodeList and array is that array gives you all kinds and longer list of methods like map,reduce. List of methods for array:methods list for array List of methods for NodeList: methods for NodeList
Day 3 code on github.

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.