Tell me, please, how to properly parse JSON data in jQuery using the exception method.

For example, the user chooses the car brand "Ваз" , then all other car brands are excluded. In the example below, 3 items from the array should remain.

 [ { "mark":"Ваз", "model":"2101" }, { "mark":"Ваз", "model":"2107" }, { "mark":" Toyota", "model":"Camry" }, { "mark":"Ваз", "model":"2121 Нива" }, { "mark":"Ford", "model":"Focus" } ] 

    1 answer 1

    You can use the filter method to filter arrays.

     var filtered = data.filter(el=>el.mark == 'Ваз'); 
    • and var filtered = data.filter(function(el){ return el.mark == 'Ваз';}); )) - Jean-Claude
    • @ Jean-Claude, it's the same thing - Grundy