Reputation:
How Can I get value from this array? I would like to take from each of Object value as firstPersonName.
I wrote something like this
var rest = email.map(a => {
a.firstPersonEmail;
});
console.log(rest);
But i am getting
Thanks for any help :)
Upvotes: 1
Views: 4606
Reputation: 63
This may help you:
var rest = email.map(a => {
return a.firstPersonEmail;
});
console.log(rest);
or
var rest = email.map(a => a.firstPersonEmail);
console.log(rest);
const email = [
{id:1, firstPersonEmail: "[email protected]"},
{id:2, firstPersonEmail: "[email protected]"},
{id:3, firstPersonEmail: "[email protected]"}
];
const emptyEmail = [];
console.log(`Email length: ${email.length}`);
console.log(`Empty Email length: ${emptyEmail.length}`);
const rest = email.map(a => a.firstPersonEmail);
const emptyRest = emptyEmail.map(a => a.firstPersonEmail);
console.log(rest);
console.log(emptyRest);
Upvotes: 3