TypeScript – Take object out of array based on attribute value

Use Array.find:

let array = [
    { id: 1, value: "itemname" },
    { id: 2, value: "itemname" }
];

let item1 = array.find(i => i.id === 1);

Array.find at MDN: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find

Leave a Comment