Using array.length property: Using array.length property, you can alter the length of the array. It helps you to decide the length up to which you want the array elements to appear in the output.
// 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 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 exists 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]