i have object of array like this:
var arr = [{id: 1, url: 'something'},{id: 2, url: 'something2'}];
i want output like this :
[{id:1}, {id:2}]
Thanks in advance
Just use Array#map
const arr = [{id: 1, url: 'something'},{id: 2, url: 'something2'}];
const mapped = arr.map(({id}) => ({ id }));
console.log(mapped);
In simple form
const arr = [{id: 1, url: 'something'},{id: 2, url: 'something2'}];
const mapped = arr.map(item => { return { id: item.id };});
console.log(mapped);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With