I'm creating an advanced search in a project in school. I'm pretty new to JavaScript, so it might be an easy question, but every suggestion or solution is very much appreciated.
We got served a JSON array which contains 15 objects in total, each containing the same keys but with different values.
It's set up on a website with different buttons which a user can check to be shown results based on their requirements.
Say if I have an array containing 3 objects:
var jsonArray = '[
{"gm": "0", "la":"1", "wh":"1", "place":"somePlace1"},
{"gm":"1", "la":"0", "wh":"1", "place":"somePlace2"},
{"gm":"0", "la":"1", "wh":"0", "place":"somePlace3"}
]';
The jsonArray is already parsed and sorted.
We're also requested to create an object representing the requirements from the user.
So if the user clicks on the button "la" and "wh" on the website, it will then create an object;
var newObject = {la:1, wh:1};
Which would give the first element in the array only.
This is how far I've gotten really. I've tried different kind of solutions from other similar questions regarding this, but couldn't quite figure it out.
How can I compare newObject with jsonArray to perhaps create a new/or update the current array with objects that contains these values? On the other keys it doesn't matter what the values are, just as long as the keys and values between jsonArray and newObject match.
Also worth noting that we're not allowed to use jQuery or anything other than JavaScript.