i have an array that looks like this
let arrayExample =
[
{
"size":"6M",
"color":"Blue"
}
,
{
"size":"2M",
"color":"Yellow"
}
]
currently, to return all elements of a specific color or a specific size I use this approach
var allColors= arrayExample.map(i=>i.color)
return [{"color":"Blue"}].some((val)=> allColors.includes(val.color))
my question is how to return a truthy value whenever i found an element with the exact combination i desire
as quoted in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some
Return value true if the callback function returns a truthy value for at least one element in the array. Otherwise, false.
my current approach to this is
var allColors= arrayExample.map(i=>i.color)
var allSizes= arrayExample.map(i=>i.size)
return [{"color":"Blue","size":"2M"}].some((val)=> allColors.includes(val.color) && allSizes.includes(val.size)
this approach doesn't work for my purposes, knowing that even if there is no item in my arrayExample with the combination [{"color":"Blue","size":"2M"}], it would still return true because of the 2M size of the 2nd item of my array
here is a Jsfiddle to test my situation https://jsfiddle.net/8htjpyb9/1/
I would like to thank you if you got this far and also thank you for any and all help, I hope you are having a good day
*edit -> i would like to emphasize that .filter does not work for my problem because of the rest of the code this situation is embedded in.
I am only interested in returning a value of true whenever it finds the exact match.