Javascript对象和数组-从一个对象到另一个对象获取价值

时间:2018-09-09 09:29:58

标签: javascript arrays object

我有两组数据。 他们两个人都有一个“ positionTitle”,我希望将一个人的positionTitle的值放在另一个人中。

第一个数据集是我要保留的数据,而第二个位置是我要更新的位置,它是一个对象,其中包含数组。

{

    "id":"00xmlAAA","name":"A","engagementAreas":
    [{"id":"a6q0X0AW","name":"","hasActiveContract":false,"
    engagements":[{"id":"a0s0X000008udz6QAA","name":"M","startDate":"2018-03- 
    22","endDa
    te":"2019-03-22","country":null,"city":null,"type":"Project","members": 
    [{"id":"a0U0X00001HNjm7UAD","account":{"id":"001b00000
    0U7vXfAAJ","fullName":"Edy Liongosari"},"badgeType":null,"endDate":"2019-03- 
    22","engagementRole":"Working Group","position":{
    "id":"a16b0000000B3tgAAC","organizationId":"001b00000062923AAA",
    "organizationName":"a","positionTitle":"Managing Director", <-- here
    "positionLevel":"4-Head of Business Unit/Head of 
    Region","isPrimary":true,"startDate":

第二组是一个带有对象的数组。

第二组-

[{"account":{"id":"001b000003WnPy1AAF","fullName":"Adnan A. Khan"},"positions":[
{"id":"a","positionTitle":"Senior Manager, Energy","positionLevel":"5-Middle Managem
nt & Advisers","isPrimary":true,"startDate":"2016-10-07","endDate":null}]},{"account":{"id":"0010
X000048DDMsQAO","fullName":"Christine Leong"},"positions":[{"id":"a160X000004nKfhQAE","organizationId":"00
1b0000005gxmlAAA","organizationName":"a","positionTitle":"Managing Director"   <-- here    ,"positionLevel":"4-Head of Bu
siness Unit/Head of Region","isPrimary":true,"startDate":"2018-03-05","endDate":null}]}
,{"account":{"id":"001b000000Gs91HAAR","fullName":"Cora Ansorg"}

*第一组数据将具有不同数量的区域,如下所示, 导致我相信带有for循环的.map方法会非常棘手,因为我没有设置要去的索引?

The first array will have a number of 'engagementareas' {[]}
This will have a number of 'engagementtypes'{[]}
this will have a number of 'engagements'{[]}
this will have a number of 'positions'{}
which will have some 'positionTitle'

我当时正在考虑使用array.map

我可以像这样console.log数据

    console.log('graph data members' + JSON.stringify(graphData.engagementAreas[0].engagementTypes[1].engagements[0].members[0].position.positionTitle))


I can think of using array.map (  (el, i) => 

el.engagementareas.engagementtypes.members[i].
position.positionTitle = a.positions[i].positionTitle


 )

0 个答案:

没有答案