I have this JSON structure, I want to create 2 arrays out of this array of JSON. one array having all the values from key “employee only” to “”Annual OOP max / entire famliy” (from each object in JSON array) and 2nd array to have values from key “Primary care doctor visit” to end of the object”.
array 1 = [86.1, 291.3, 121.4 ………..6550,”$13,100 family”]
array 2 = [“75% covered after deductible”, “75% covered after deductible”,”$4 copay Doctor on Demand”,…………, “See HMO provider”] How can i achieve this in 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" } ]
Advertisement
Answer
You need something similar to this. Just add all the elements you want one by one as in the example below. Do the same for the other array (myArray is the json array)
var array1 = myArray.map(function(item) { return [item["employee Only"], item["employee + Spouse/Partner"], item["Annual OOP max / entire famliy"] ] }).join(',').split(',');