gpt4 book ai didi

JavaScript 映射为某些元素返回未定义

转载 作者:搜寻专家 更新时间:2023-11-01 04:59:29 25 4
gpt4 key购买 nike

<分区>

给定以下成员数据数组,我将为成员资格状态不是最新的成员返回一组 memberID

这是成员数据:

var members = [
{
firstName: 'Howard',
lastName: 'Lee',
membershipIsCurrent: true,
MemberID: 235
},
{
firstName: 'James',
lastName: 'Icharis',
membershipIsCurrent: false,
MemberID: 236
},
{
firstName: 'Thomas',
lastName: 'Cronquist',
membershipIsCurrent: true,
MemberID: 237
},
{
firstName: 'Philip',
lastName: 'Grover',
membershipIsCurrent: false,
MemberID: 238
},
{
firstName: 'Eric',
lastName: 'Broadstone',
membershipIsCurrent: true,
MemberID: 239
},
{
firstName: 'Hunter',
lastName: 'Gonzales',
membershipIsCurrent: true,
MemberID: 240
}];

这是我获取该数据的代码:

function lapsedIDs (array ) {
return array.map( function ( member ) {
if ( member.membershipIsCurrent === false ) {
return member.MemberID;
}
});
}

lapsedIDs(members);

这是结果。我不明白为什么它会为每个成员资格尚未失效的成员返回 undefined。有什么指点吗??

[ undefined, 236, undefined, 238, undefined, undefined ]

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