The take
function from lodash is used to create a new array containing the first n elements of a given array. The syntax for using take
in JavaScript is as follows:
index.tsx22 chars2 lines
Here, array
is the input array from which the first n
elements are to be extracted. n
is an optional parameter that specifies the number of elements to be extracted from the beginning of the array. If n
is not specified, only the first element of the array is returned.
Below is an example of using take
function:
index.tsx145 chars10 lines
In the above example, the take
function is used to extract the first 3 elements from the arr
array. The output of the program is [1, 2, 3]
.
gistlibby LogSnag