Let's assume that we define the following array of objects:
javascriptlet tees = [ { color: 'pink', price: 10 }, { color: 'red', price: 20 }, { color: 'black', price: 30 } ];
If we want to filter an object in the array depending on the color:
javascript// We filter the pink tee let filtered = tees.filter(tee => tee.color === 'pink'); // We get the first element of the filtered array let tee = filtered[0]; console.log(tee); // {color: 'pink', price: 10}
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.