I want reduce an array of object, eg.:
const users = [
{id: 1, username: 'foo'},
{id: 2, username: 'bar'},
{id: 3, username: 'baz'}
];
to an array of id, eg.:
users.reduce( magicReducer ); // output: [1,2,3]
is possible?
I want reduce an array of object, eg.:
const users = [
{id: 1, username: 'foo'},
{id: 2, username: 'bar'},
{id: 3, username: 'baz'}
];
to an array of id, eg.:
users.reduce( magicReducer ); // output: [1,2,3]
is possible?
This should solve the problem for you !
const users = [{id: 1, username: 'foo'}, {id: 2, username: 'bar'}, {id: 3, username: 'baz'}];
console.log(users.map(user => user.id))
try this
const users = [
{id: 1, username: 'foo'},
{id: 2, username: 'bar'},
{id: 3, username: 'baz'}
];
ids=users.map(x=>x.id)
console.log(ids)