EDIT: Question has been updated.
The format you want the data in ([{1},{2}]) cannot be achieved. A javascript object has to have a key and a value. so, {1} is invalid.
But on the other hand if it's just the ids you want ([1,2]), see the mapping below and instead of returning {id: item.id}, just return item.id.
var data = [{ id:1, name: 'Adam', email: '[email protected]', age: 12},
{ id:2, name: 'Amalie', email: '[email protected]', age: 12}];
// [{id: 1, {id: 2}}]
var data_id = data.map(function(item){
return { id: item.id};
});
// [1, 2]
var data_id = data.map(function(item){
return item.id;
});
If you're using ES6, you could simplify the code
var data_id = data.map(item => ({ id: item.id}));
You can use javascript map function to extract just the id.
See https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/map