gpt4 book ai didi

javascript - Angular2 从对象数组中获取值

转载 作者:行者123 更新时间:2023-11-30 11:43:21 24 4
gpt4 key购买 nike

如何从这个数组中获取值?我想从每个 Object 值中获取 firstPersonName。

enter image description here

我是这样写的

var rest = email.map(a => {
a.firstPersonEmail;
});
console.log(rest);

但是我得到了

enter image description here

感谢您的帮助:)

最佳答案

这可能对您有帮助:

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);

关于javascript - Angular2 从对象数组中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41869166/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com