javascript - Using Array.every() function to check if all values are defined -
i trying check if values defined in array of mine. code following
var check = function (item){return item !== undefined;}; array.every(check); i tried on next arrays:
var array = []; array[5] = 0; //[undefined × 5, 0] array.every(check); //return true although there 5 udefined values there what doing wrong?
as said above every skips "holes".
if want functionality can add together simple method:
array.prototype.myevery= function (pred) { (var = 0; < this.length; i++) { if (!pred(this[i])) homecoming false; } homecoming true; } javascript arrays
No comments:
Post a Comment