Javascript – Loop through nested object

I have 1 array with multiple object and an object. How do i find and return the data matching that object. Here is an illustration of my code.

const cars = [{model:"honda", color:"black", features:[{title:"fast",speed:"100mph"}]}]

const feature = {id:1,title:"fast",speed:"100mph"} 

const match = cars.filter(car => car.features.includes(feature))     

This should return

{model:"honda", color:"black", features:[{title:"fast",speed:"100mph"}]}

but it does not and not sure why. Can someone help?

27 thoughts on “Javascript – Loop through nested object”

Leave a Comment