I'm facing a simple array dilemma: I have two separate arrays - one containing strings and the other containing objects. What I need to do is compare them in a specific manner: The array of objects should verify if a property of each object is present in the array of strings, and then provide a response for each case.
const colors = ["blue", "pink", "red", "green", "yellow", "orange", "white"]
const objColors = [{name:"pink", value: true}, {name:"green", value: true}, {name: "white", value: false}]
The expected resulting array should look like this:
const res = [false, true, false, true, false, false, false]
I've been struggling to find a solution despite my various attempts. I experimented with double iterations which led to inaccurate results. Additionally, I attempted using the includes method but that only allowed me to check the objColors array, leaving some cases unchecked.
let res = objects.map(x => (strings.includes(x.name)))
If anyone could offer me some guidance on how to approach this problem to achieve the desired outcome, I would greatly appreciate it. Thank you in advance.