我如何从这个数组获得价值?我想从每个Object值中取出firstPersonName。
我写了这样的东西
var rest = email.map(a => {
a.firstPersonEmail;
});
console.log(rest);
但我得到了
感谢您的帮助:)
答案 0 :(得分:3)
这可能会对您有所帮助:
var rest = email.map(a => {
return a.firstPersonEmail;
});
console.log(rest);
或
var rest = email.map(a => a.firstPersonEmail);
console.log(rest);
const email = [
{id:1, firstPersonEmail: "John@mail.mail"},
{id:2, firstPersonEmail: "John2@mail.mail"},
{id:3, firstPersonEmail: "John3@mail.mail"}
];
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);