07 Arrays - Gilian/001-ES6-By-Wes GitHub Wiki

Array.from()

It is important to know that they are not on the prototype, so you can't call them directly on arrays. You can use this to convert arrayish elements into real arrays to access their prototype, like arguments or NodeLists.

In the example we use the second parameter to loop over each element:

// Create an Array from a DOM-List
const people = document.querySelectorAll('.people p');
const peopleArray = Array.from(people, person => {
   return person.textContent;
}

Array.of()

Takes in all the arguments you want to convert into an array

Array.find() & Array.findIndex()

// Imagine there is a list of objects. you want to find a specific ID in 'code'
const code = 'VBgtGQcSf';
const post = posts.find(post => post.code === code);
// or return the index, so you can delete the item i.e.
const postIndex = posts.findIndex(post => post.code === code);

Array.some()

Is there at least one item in the array that match.

Array.every()

Do every item match.

// Example for some() und every()
const ages = [32, 15, 19, 12];

// is there at least one adult in the group?
const adultPresent = ages.some(age => age >= 18);
// --> returns true 

// is everyone old enough to drink?
const allOldEnough = ages.every(age => age >= 19);
// --> returns false