TypeScript - Take object out of array based on attribute value

后端 未结 5 1802
名媛妹妹
名媛妹妹 2020-12-29 00:54

My array looks like this:

array = [object {id: 1, value: \"itemname\"}, object {id: 2, value: \"itemname\"}, ...]

all my objects have the s

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 01:19

    Below worked for me.

    let array = [
        { id: 1, value: "itemname" },
        { id: 2, value: "itemname" }
    ];
    
    let item1 = array.find(i => i.id === 1);
    

提交回复
热议问题