Good question, in that case, another search would have to be implemented on the nested object, something like: topLevelData.nestedObject and this would pass for our search array.
Hope I've answered your question Haidar?
There's a library called fusejs that flattens out objects with nested arrays. It checks the type of each value and if array recurses. All in order to create one big flat object you can search in.
What if you have nested objects?
Good question, in that case, another search would have to be implemented on the nested object, something like:
topLevelData.nestedObject
and this would pass for our search array.Hope I've answered your question Haidar?
Yes but not really scalable. What if you have more than 3 level of nesting. I think you could improve your function a bit
There's a library called fusejs that flattens out objects with nested arrays. It checks the type of each value and if array recurses. All in order to create one big flat object you can search in.
Thanks for sharing John.
You might find fusejs interesting as a search library - the "flattening" process is part of how it searches rather than main function.
You do object.values on the json items. Then do stringify on the item values. Than call includes on that string.
Not sure about performance though.