Arrays in JavaScript — Part 2

📄 Table of Contents

Array Methods

Array find() Method

var ages = [3, 10, 18, 20];

function checkAdult(age) {
return age >= 18;
}

function myFunction() {
document.getElementById("demo").innerHTML = ages.find(checkAdult);
}

Array some() Method

Array.fill()

Array.from()

Array.find()

Array.findIndex()

Array.of()

When to use forEach?

When to use map?

When to use filter?

let chars = ['A', 'B', 'A', 'C', 'B'];let uniqueChars = chars.filter((c, index) => {
return chars.indexOf(c) === index;
});
console.log(uniqueChars);
[ 'A', 'B', 'C' ]Code language: JSON / JSON with Comments (json)
let chars = ['A', 'B', 'A', 'C', 'B'];let dupChars = chars.filter((c, index) => {
return chars.indexOf(c) !== index;
});
console.log(dupChars);Code language: JavaScript (javascript)
[ 'A', 'B' ]

When to use find?

When to use reduce?

Quirks and Criticisms

forEach returns undefined.

const arr = [1,2,3];const transformedArr = arr.map(function(){}).filter(function(){});

A word about speed.

Experience with Front-end Technologies and MERN / MEAN Stack. Working on all Major UI Frameworks like React, Angular.