- Array.prototype.some(); is there at least one match? Returns true or false.
- Array.prototype.every(); every single item in array matches to the condition or not? Returns true or false.
- console.log({variable}); - in console can be seen like
isAdult:true
- Array.prototype.find(); Find is like filter, but instead returns just the one you are looking for
- 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);
- 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);
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