6/12/2023 0 Comments Slice in javascript arrayThis example should help give a basic idea as to why the lodash slice method is a tad more robust compared to the native counterpart. 3.1 - Using Array map on two arrays that are the result of calling Lodash slice and Array slice with a sparse array The native Array slice method will not do this for me. The lodash array method will account for this, and the resulting array that is returned will have empty array elements filled with the value undefined. There are holes in the array sort of speak where there is not value at all, not even an undefined or null value, just no key at all. When doing so the resulting Array is a ‘sparse array’, that is that it is basically just an object with a length property when it comes to the public key values. One way to create a sparse array is to use the Array constructor and pass a length for the array that is say 3 elements. The difference between the two has to do with the absence or presence of empty elements in the array. So far the examples of the Array slice and lodash slice methods involved the use of dense arrays rather than sparse arrays. 3 - Sparse Arrays and the lodash slice vs Array slice methods The differences between these two kinds of arrays is where the lodash slice method is a little more robust. However this basic arrays of numbers is often called a ‘dense array’, rather than a ‘sparse array’. Same result when it comes to this simple array of numbers sure.
0 Comments
Leave a Reply. |