-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
  • 9,107
  • 3
  • 12
  • 28
user2799827
  • 861
  • 1
  • 16
  • 38

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);
Rajan
  • 4,939
  • 1
  • 5
  • 17