Simplify your JavaScript – Use .some() and .find()
javascript - Why Array.some() method behaving differently? - Stack Overflow
[AskJS] Some advice on web scraping with Javascript.
[AskJS] What are some advanced Javascript concepts/methods one needs to know before learning frameworks?
Videos
See MDN:
The some() method executes the callbackFn function once for each element present in the array until it finds the one where callbackFn returns a truthy value (a value that becomes true when converted to a Boolean). If such an element is found, some() immediately returns true. Otherwise, some() returns false. callbackFn is invoked only for indexes of the array with assigned values. It is not invoked for indexes which have been deleted or which have never been assigned values.
You can see that here:
const arr = ['item 1', 'item 2', , 'item 3', , 'item 4', 'item 5'];
console.log(arr.some((item, index) => {
console.log(item, index);
return !item
}));
If I will explicitly replace the empty elements with undefined, then it will return true.
That's the difference between "never assigned a value" and "been assigned the undefined value".
The elements are actually empty and not undefined
const arr = ['item 1', 'item 2', , 'item 3', , 'item 4', 'item 5'];
// If you see in console, empty element has been filled with undefined
console.log(arr);
VM146:4 (7) ['item 1', 'item 2', empty, 'item 3', empty, 'item 4', 'item 5']
Thats the reason the some script behaves differently. This thread does a good job on explaining stuff
Check the array has empty element or not