Can't make a function that finds the value using the key with a JSON array
using jQuery
I am trying to build a calculator which uses data from JSON file. I cannot
change the way the data is keyed or labeled in the JSON file since it is
generated from a CSV file.
My JSON data looks like this (I am using a grep filter and then storing it
in a variable but for brevity I am not showing that part unless someone
needs to see it):
var medicare = {
"": "",
"80101": "NC",
"80104": "NC",
"80152": "24.61",
"80154": "22.72",
"80299": "18.83",
"82055": "14.85",
"82145": "9.71",
"82542": "16.01",
"82646": "23.91",
"82649": "23.91",
"83805": "24.23",
"83840": "13.04",
"83887": "22.26",
"83925": "26.74",
"83992": "20.20",
"99080": "NC",
"99358": "NC",
"Carrier Type": "Medicare",
"G0434": "12.17",
"State": "Minnesota",
"id": 122
}
And I need to create a function that will be able to return the value of
any of the given keys.
function findInside( array, key ) {
return array[key]; // <-- This is my problem.
}
Which I can use to return value by running:
console.log(findInside(medicare, "80101"))
I just need to be able to get the value. I don't think I need to do any
loops and such. I'm still new to JavaScript and am banging my head over
this one, and it should be pretty easy.
Thanks in advance!
No comments:
Post a Comment