JavaScript Tip: Working with Sparse Arrays

preview_player
Показать описание
In this tutorial we cover how to deal with sparse arrays, or values of undefined and null inside an array. These concepts can be helpful when working with arrays.

For more resources on JavaScript:

Courses offered on Udemy: Getting Started or Advanced Topics at a huge discount:

Tutorials referred to in this video:

#javascript #AllThingsJavaScriptLLC
Рекомендации по теме
Комментарии
Автор

Thanks for another great video!
Just an observation here, we can filter out all null, undefined and 'empty' values with one filter method like this:
<pre>
let arr = [1, undefined, null, , 2, 3];
let filt = arr.filter(val => {
return val;
});
console.log(filt); // [1, 2, 3]
</pre>
It works cause undefined and null are falsy values and filter method ignores 'empty's.

aleksandregorov
Автор

Thank you for the great videos, about the for in loop.. isn't that for looping over objects and for of loop for arrays? (I know in js arrays are objecta but still I wonder if its right :) )

Alexandru-OM
Автор

but why length -1 it will skip last element of array

codelivewithme