在params.value
中,我有3个数组,其中我需要将Names放在一个变量中。我尝试通过ForEach
做但我做不到,出了什么问题?
var roles = params.forEach(x => params.value.Name);
return roles;
{"Object":[{"TerritoryId":1,"TerritoryName":"Russia","FirmPieRotationRuleId":1,"FirmPieWorkedYears":0,"FirmPieCoolOff":5,"FirmPieRoles":[{"TeamRoleId":1,"Name":"Engagement Leader","MinCount":1,"MaxCount":1,"SortOrder":0},{"TeamRoleId":2,"Name":"Signing Partner","MinCount":1,"MaxCount":1,"SortOrder":0},{"TeamRoleId":3,"Name":"Engagement Manager","MinCount":1,"MaxCount":1,"SortOrder":0}],"StatutoryPieRotationRuleId":null,"StatutoryPieWorkedYears":null,"StatutoryPieCoolOff":null,"StatutoryPieRoles":[],"NonPieRotationRuleId":null,"NonPieWorkedYears":null,"NonPieCoolOff":null,"NonPieRoles":[]}],"Code":0,"ErrorMessage":null,"Errors":[]}
答案 0 :(得分:2)
Array#forEach
不会返回任何内容。请尝试使用Array#map
。
var roles = params.map(x => params.value.Name);
答案 1 :(得分:0)
value
是数组。试试这个:
var roles = params.value.map(val => val.Name)