[英]how to map an array in an object map to another array
我有一个对象
{
"parent_entity_id": 394,
"display_name": "Test POI",
"event_code_prefix": "TEST",
"address": null,
"logo_url": "https://storage.png",
"is_active": true,
"identifier": [
{
"model_id": 10,
"entity_id": 575,
"is_active": true,
"valid_value": [
{
"type": "MACID",
"value": "AC:23:3F:23:8D:A1"
}
],
"display_name": "Test BLE Beacon 1",
"is_mandatory": true,
"entity_type_key": "BTBACID"
},
{
"model_id": null,
"entity_id": 576,
"is_active": true,
"valid_value": [
{
"type": "GEOFENCE_CIRCLE",
"value": {
"latitude": 24.155678,
"longitude": 54.425175,
"radius_in_meters": 500
}
}
],
"display_name": "Test tower gate 1",
"is_mandatory": true,
"entity_type_key": "GIS"
}
]
}
我需要将数组有效值从对象映射到另一个有条件的数组。 如果 Ble 映射到 valid_value_BLE 数组,如果 GIS 到 valid_values_GIS
尝试这个
arr1=Obj.identifier.map(z => {
if(z.entity_type_key=='GIS'){z['valid_value_GIS']=z.valid_value;
}else{z['valid_value_BLE']=z.valid_value;}
delete z.valid_value; return z;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.