-1

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.

Ramesh Reddy
  • 10,159
  • 3
  • 17
  • 32
user2799827
  • 1,077
  • 3
  • 18
  • 54

1 Answers1

0

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);
gorak
  • 5,233
  • 1
  • 7
  • 19