Arrays are one of the simplest data structures which allow access to a list of elements. JavaScript (and most programming languages) has the notion of array. However one of the problems related to arrays is they are constrained by their size, i.e. an array has a limited number of elements. Furthermore, when applying functions to arrays, one passes the whole data structure at once. Let’s take a look at the following example. The map function is applied to the whole array and the result is calculated right away.
1 2 3 |
var source = [4, 6, 8, 9]; var mapped = source.map(x => x * 2); // mapped is [8, 12, 16, 18] |
Note, the lambda expression is part of ES6