Skip to content
Advertisement

How to filter a multi dimensional json file to match the input value

I am triying filter a json file to match the input value. I write the code below. The json file is multi dimensional.

JavaScript
JavaScript

I need to match input with key 4 and need to remove duplicate values. How to do it? I tried with

states.key3.filter(…state.key4 but it give errors

Advertisement

Answer

This will show the object that has a key4 value exactly equal to the search input:

JavaScript
JavaScript

And for matching values that starts with the search input value you can do this:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement