Created
January 3, 2021 14:51
-
-
Save Jagathishrex/88e13b110d54b0c3be46d27f0d09aefe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let num = new Array(3); // creating an empty array with length 3 | |
console.log(num); // [empty × 3] | |
console.log(num[0]); // undefined | |
// the callback function passed to Array.some method will not check the callback for unassigned values | |
num.some(a => {console.log(a); return a === undefined }) // false | |
// But Array.findIndex will check the callback function for unassigned values also | |
num.findIndex(a => {console.log(a); return a === undefined }) // undefined will be printed - 0 will be returned |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment