0

I'm currently working on some data chart implementation on a website, and I have a JSON with some data, notably some ID numbers, some dates, and some datapoints. Because I have multiple dates under the same ID, I'm looking for a way to do what is essentially "Find the JSON object that has this ID and Month, then get the datapoint numbers from that object". Any help on how I would accomplish this? Preferably without iteration, if possible, as the file is extremely large. I'll include an example of what the JSON looks like:

[{
"ID" : "32",
"month" : "6",
"value" : "438"
},
{
"ID" : "32",
"month" : "5",
"value" : "223"
}

It should also be noted that the ID's aren't grouped together like this in the actual json, this is just an example. Also changing the json contents is not an option.

Any help is greatly appreciated, thank you!

1 Answers1

0

In JS you could use array.find.

Something like res = myArray.find(item => item["ID"] === "32" && item["month"] === "5").

Then res is the object your searching for.


If you want to accomplish lookups without any iteration you'd need to generate a data structure with unique keys, ie. make a new object with keys something like id-month.

Malcolm
  • 150
  • 5