Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript filter array of objects by id

const myArray = [{id: 1, name:'pipi'}, {id: 2, name:'popo'}];
const id = 2;

const variableOne = myArray.filter(itemInArray => itemInArray.id === id);
console.log(cariableOne[0].name);
 
PREVIOUS NEXT
Tagged: #javascript #filter #array #objects #id
ADD COMMENT
Topic
Name
7+5 =