如何仅发送一个数组值(不包含两个值)?

时间:2019-02-11 04:20:52

标签: reactjs

id: "a4a1e57b-f1c2-4a22-8b99-1ce2466719ba"
meetingDate: "2019-02-10T19:48:45"
members: [{memberId: "99489ea4-6d34-11e8-80cd-001dd8b71cd8", memberCode: "00-005424",…}]
0: {memberId: "99489ea4-6d34-11e8-80cd-001dd8b71cd8", memberCode: "00-005424",…}
   fullName: "Бағидолла Нұрсұлтан Маратұлы"// this 3 
   memberCode: "00-005424"
   memberId: "99489ea4-6d34-11e8-80cd-001dd8b71cd8"

我只需要在成员数组中发送带有(,)的memberId值,该怎么做?像

members [( 0: "99489ea4-6d34-11e8-80cd-001dd8b71cd8", 1: "99489ea4-6d34-11e8-80cd-001dd8b71cd8", 2: "99489ea4-6d34-11e8-80cd-001dd8b71cd8")]

1 个答案:

答案 0 :(得分:0)

您可以使用Array.map

var memberIds = members.map( m => m.memberId)

这将从您给定的数据结构中选择成员ID,并将其存储在新数组中

然后您可以更改原始结构

{
  ... // other props
  members: memberIds
}

由于不建议进行突变,所以我建议创建一个原始数据的克隆,然后将其突变