I have an array of thousands objects and need to check if a specific value is included in one of the values.
My array:
const images = [
{
"name" : "sky",
"width" : "90",
"height" : "150",
"colours" : ["pink", "yellow", "red"],
},
{
"name" : "old car",
"width" : "90",
"height" : "150",
"colours" : ["dark purple", "sand", "light green"],
},
{
"name" : "sky",
"width" : "90",
"height" : "150",
"colours" : ["dark blue", "violet"],
},
...
]
and I'm trying to get a new array that contains only those objects which include a specific colour. Also the value must be a perfect match: i.e. if I pass "blue" it should return false if it checks against "dark blue"
I'm trying to do the following but running into errors
const checkColourtHandler = async (selectedColour) => {
const imageList = images.filter(function (item, i) {
if (item.colours.includes(selectedColour)) {
return true;
} else return false;
});
console.log(imageList);
}
Ideally I'm looking for the best performant method as well.