Using Array Filter () method in JavaScript, compress sparse array

What is a sparse array

The index of the array element is not necessarily continuous, and there is no time between them. Each JavaScript array has a length attribute. In response to non-populated arrays, this attribute is the number of array elements; for sparse arrays, Length is larger than the number of all elements.

Array Filter () method will skip the missing elements in the sparse array, and its return array is always dense.

(1) vaccies in compressed sparse array:

VAR DENSE = sparse.filter (burRentValue) {Return True;});

Airlines of the sparse array, and delete undefined and null elements:
VAR DENSE = sparse.filter (CurrentValue) {Return CurrentValue! == Undefined && currentValue! = null;})


It is a small compression to the JavaScript to use the array filter () method to compress the sparse array. I hope that everyone can help. If you have any questions, please leave a message, the small package will reply to everyone. Thank you very much for your support of Tumi Cloud Website!

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment