javascript filter array of objects by id

Solutions on MaxInterview for javascript filter array of objects by id by the best coders in the world

showing results for - "javascript filter array of objects by id"
Erica
17 Jan 2017
1const myArray = [{id: 1, name:'pipi'}, {id: 2, name:'popo'}];
2const id = 2;
3
4const variableOne = myArray.filter(itemInArray => itemInArray.id === id);
5console.log(cariableOne[0].name);