// n = number of elements you want to print var_name.length = n;
In the above syntax, you can assign the size to the array using the array.length property according to the required output.
[1, 2, 3]
As you can see in the above output, only three elements get printed. Assigning a value to the array.length property truncates the array and only the first n values exist after the program.
Using splice() Method: The splice() method removes items from an array, and returns the removed items.
// n=number of elements you want to print var_name.splice(n);
[1, 2, 3, 4]
Please Login to comment...