javascript forEach return
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));const list = [{ name: "John", age: 36 },{ name: "Jack", age: 17 }];
// if you just have to FIND an object with a specific value,
// use Array.prototype.find:
const foundHim = list.find( person => person.name === "John" );
console.log( foundHim );
// if you still want to / need to RETURN the object / value
let returnedHim;
list.forEach( person => {
if ( person.age === 17 ) {
returnedHim = person;
}
});
console.log( returnedHim )function double(arr) {
return arr.forEach(num => num*2);
}
console.log(double([1,2,3,4])) //undefined
Also in JavaScript:
- javascript reverse each string element in array
- js check if number has decimals
- Error: Can't resolve 'fs' webpack
- mongodb distancefield to kms
- /runtime.d7bbc2cdb230ca3d1157.js
- jquery get class name
- how to add button in javascript
- javascript send post
- reactjs context
- app.js:38650 [Vue warn]: Failed to mount component: template or render function not defined
- get radio button value javascript
- li dots
- w3 js resize event
- vendor bundle base js and bootstrap min js conflict
- vue test utils mapgetter
- react dark mode npm
- variables 2 python .Bartolome sintes Marco
- javascript string change character at index
- get epoch timestamp js
- conditional style react
- react native animation libraries
- col to right bootstrap
- map a square to a circle
- what does appendchild do in javascript