What do you want to save?
Add Code snippet
New code examples
-
Javascript 2021-09-27 05:26:04
update object in array if id exists else append javascript
function upsert(array, item) { // (1) const i = array.findIndex(_item => _item.id === item.id); if (i > -1) array[i] = item; // (2) else array.push(item); } const array = [ {id: 0, name: 'Apple', description: 'fruit'}, {id: 1, name: 'Bana... Add solution -
Javascript 2021-09-13 22:41:03
find the matching property
var todos = [ { item: 'Wash the dog', added: 2018-03-22, completed: false }, { item: 'Plan surprise party for Bailey', added: 2018-03-14, completed: false }, { item: 'Go see Black Panther', added: 2018-03-12, completed: true }, { ... Add solution -
Javascript 2021-09-11 04:41:02
javascript array patch object in array
//Initailize array of objects. let myArray = [ {id: 0, name: "Jhon"}, {id: 1, name: "Sara"}, {id: 2, name: "Domnic"}, {id: 3, name: "Bravo"} ], //Find index of specific object using findIndex method. ... Add solution -
Javascript 2021-09-08 09:27:04
javascript find object array
myArray.findIndex(x => x.id === '45'); Add solution -
Javascript 2021-09-05 07:17:02
find in javascript
const simpleArray = [3, 5, 7, 15]; const objectArray = [{ name: 'John' }, { name: 'Emma' }] console.log( simpleArray.find(e => e === 7) ) // expected output 7 console.log( simpleArray.find(e => e === 10) ) // expected output undefined console.log... Add solution