I have a JSON object with items that I need to analyze in JavaScript. When I view the JSON in the console, there is an element called items
that contains an array of relevant information.
console.log(json)
{current_page: 1, per_page: 100, total_entries: 106, items: Array(100)}
current_page:1
items:Array(100)
0:{id: 15814, name: "Vehicle_1001", state: "available", repair_state: "broken", network_id: 99, …}
1:{id: 16519, name: "Vehicle_1002", state: "available", repair_state: "broken", network_id: 99, …}
However, when I attempt to use the filter
function to count the number of records where repair_state
is set to broken
, I encounter an error:
json.filter(value => value.items.repair_state === 'broken').length
Uncaught TypeError: json.filter is not a function
What am I doing incorrectly and how can I determine the count of items
with a repair_state
property equal to broken
in this scenario?