QP School

Full Version: Add elements at the beginning of an array in JavaScript
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
var numbers = [1, 2, 3, 4, 5];
var num1 = -1;
var num2 = 0;

numbers.unshift(num1, num2);

document.write(numbers);