QP School
Add elements at the beginning of an array in JavaScript - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: JavaScript Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=6)
+--- Thread: Add elements at the beginning of an array in JavaScript (/showthread.php?tid=4081)



Add elements at the beginning of an array in JavaScript - Qomplainerz - 04-04-2023

Code:
var numbers = [1, 2, 3, 4, 5];
var num1 = -1;
var num2 = 0;

numbers.unshift(num1, num2);

document.write(numbers);