I want a nested object which has a specific property value to return truthy with my find() function and breadth-first-search algorithm.
The object is nested six layers from the entry point.
The function is returning null. How do I get this function to return truthy?
Here's the entry point's selector -
yearColumns = document.querySelectorAll(".Table.Table--align-right.Table--fixed.Table--fixed-left");
Here's the desired object's location when you open it's ancestors properties and descendants in devtools -
yearColumns[0].children[2].children[5].children[1].children[0].children[1].innerText
Here's the url where my selector is and where my function is ran in the console -
https://www.espn.com/nfl/player/stats/_/id/2580/drew-brees
Here's my code...
yearColumns = document.querySelectorAll(".Table.Table--align-right.Table--fixed.Table--fixed-left");
function find(array, criteriaFn) {
let current = array
let next = []
while (current || current === 0) {
if (criteriaFn(current)) {
return current
}
if (Array.isArray(current)) {
for (let i = 0; i < current.length; i++) {
next.push(current[i])
}
}
current = next.shift()
}
return null
}
find(Array.from(yearColumns), obj => obj.innerText == "NO");
