EN
JavaScript - truncate array
0
points
In this article, we would like to show you how to truncate array in JavaScript.
Practical example
In this example, we use slice() method to truncate an array. The slice() method returns a shallow copy of an array from startIndex to endIndex (excluded).
// ONLINE-RUNNER:browser;
var array = [1, 2, 3, 4, 5];
array = array.slice(0, 3); // slice(startIndex, endIndex)
console.log(array); // [ 1, 2, 3 ]