I have an array of javascript objects and i need to return just the id and the corresponding value to end with an array that looks something like:
[{"id":"groupID123"}, {"id":"groupID321"}]
so that I can submit it to an API.
I have an array of javascript objects and i need to return just the id and the corresponding value to end with an array that looks something like:
[{"id":"groupID123"}, {"id":"groupID321"}]
so that I can submit it to an API.
You can simply map it:
var array=[{"id":"groupID123", "someKey":'Key1'}, {"id":"groupID321", 'someKey':'Key2'}];
var result1 = array.map(({id})=>id);
console.log(result1);
// OR
var result2 = array.map(({id})=>({id}));
console.log(result2);