does forEach return array javascript code example
Example 1: array.foreach
const arr = [0, 3, "hola", "hello", ";", true, [3, 6, 1]];
arr.forEach((element, index) => {
console.log(element, index);
});
Example 2: javascript forEach return
const list = [{ name: "John", age: 36 },{ name: "Jack", age: 17 }];
const foundHim = list.find( person => person.name === "John" );
console.log( foundHim );
let returnedHim;
list.forEach( person => {
if ( person.age === 17 ) {
returnedHim = person;
}
});
console.log( returnedHim )