繁体   English   中英

如何从对象数组中创建一个新数组?

[英]How to create a new array out of array of objects?

我有这个 JSON 结构,我想从这个 JSON 数组中创建 2 个 arrays。 一个数组具有从键“仅限员工”到“年度 OOP 最大值/整个家庭”的所有值(从 JSON 数组中的每个 object 中的每个 object 到“医生就诊”到“医生就诊”数组的“结束值”数组) .

数组 1 = [86.1, 291.3, 121.4...........6550,"$13,100 家庭"]

数组 2 = [“自付额后承保的 75%”、“自付额后承保的 75%”、“4 美元共付额按需医生”、............、“咨询 HMO 提供者”] 我该如何在 javascript 中实现这个?

 [ { "Provider ID": 0, "Broker ID": 16, "[Plan name, employee-facing]": "Contribution Plan", "employee Only": 86.1, "employee + Spouse/Partner": 291.3, "employee + Child(ren)": 121.4, "employee + Family": 311.9, " max contrib. / employee only": "Credited to your HRA:\n$250", " max contrib. / employee + dependents": "Credited to your HRA:\n$500", "Annual ded. / employee only": 1750, "Annual ded. / employee + dependents": 3500, "Annual OOP max / per person": 6850, "Annual OOP max / entire famliy": 13700, "Primary care doctor visit": "75% covered after deductible", "Specialist doctor visit": "75% covered after deductible", "Virtual doctor visit": "$4 copay Doctor on Demand", "Eligible preventive care": "100% covered, no deductible", "Centers of Excellence": "100% covered, no deductible", "Urgent care": "75% covered after deductible", "Emergency": "$300 copay, then 75% covered after deductible", "Hospitalization": "75% covered after deductible", "Generic drugs": 4, "Brand-name drugs": "$50 or 25% of allowed cost*", "Speciality drugs": "$50 or 20% of allowed cost*" }, { "Provider ID": 0, "Broker ID": 23, "[Plan name, employee-facing]": "Premier Plan", "employee Only": 30.5, "employee + Spouse/Partner": 154.1, "employee + Child(ren)": 48.8, "employee + Family": 180.8, " max contrib. / employee only": "None", " max contrib. / employee + dependents": "None", "Annual ded. / employee only": 2750, "Annual ded. / employee + dependents": 5500, "Annual OOP max / per person": 6850, "Annual OOP max / entire famliy": 13700, "Primary care doctor visit": "$35 copay", "Specialist doctor visit": "$75 copay", "Virtual doctor visit": "$4 copay Doctor on Demand", "Eligible preventive care": "100% covered, no deductible", "Centers of Excellence": "100% covered, no deductible", "Urgent care": "$75 copay", "Emergency": "$300 copay, then 75% covered after deductible", "Hospitalization": "75% covered after deductible", "Generic drugs": 4, "Brand-name drugs": "$50 or 25% of allowed cost*", "Speciality drugs": "$50 or 20% of allowed cost*" }, { "Benefit/feature": null, "Provider ID": 197, "[Plan name, employee-facing]": "Kaiser California Low Option South HMO", "employee Only": 33.2, "employee + Spouse/Partner": 121.2, "employee + Child(ren)": 46.7, "employee + Family": 138, " max contrib. / employee only": "None", " max contrib. / employee + dependents": "None", "Annual ded. / employee only": "$1,500 individual", "Annual ded. / employee + dependents": "$3,000 family", "Annual OOP max / per person": "$6,550 individual", "Annual OOP max / entire famliy": "$13,100 family", "Eligible preventive care services": "100% covered, no deductible", "Primary care physician visits": 35, "Specialists": 50, "Centers of Excellence": "Not available", "Virtual doctor visits": "Not available", "Hospitalization": "75% covered after deductible", "Emergency": "75% covered after deductible", "Urgent care": "75% covered after deductible", "Generic drugs": 10, "Brand-name drugs": 50, "Speciality drugs": "See HMO provider" } ]

你需要类似的东西。 只需将您想要的所有元素一一添加,如下例所示。 对另一个阵列执行相同操作(myArray 是 json 阵列)

var array1 = myArray.map(function(item) {
  return [item["employee Only"],
    item["employee + Spouse/Partner"],
    item["Annual OOP max / entire famliy"]
  ]
}).join(',').split(',');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM