I have below array of object.
items = [ { id: 0, title: "first item"}, { id: 1, title: "Second item"}, { id: 2, title: "third item"}];
What I want as another array of object from items object :
idOfItems = [ { id: 0}, { id: 1}, { id: 2}];
I have below array of object.
items = [ { id: 0, title: "first item"}, { id: 1, title: "Second item"}, { id: 2, title: "third item"}];
What I want as another array of object from items object :
idOfItems = [ { id: 0}, { id: 1}, { id: 2}];
I suggest you use the map function.
const idOfItems = items.map(i => ({ id: i.id }));
This returns the array in the format you need.