The _.slice()
method gets a slice from an array. It takes two indexes: the starting and ending index, where the starting index is inclusive and the ending is exclusive.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Lodash Tutorial</title>
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>
<script type="text/javascript">
// Getting array slice
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9];
let c2 = _.slice(nums, 2, 6);
console.log(c2);
let c3 = _.slice(nums, 0, 8);
console.log(c3);
</script>
</head>
<body></body>
</html>
Output :
[3, 4, 5, 6]
[1, 2, 3, 4, 5, 6, 7, 8]