Sunday, May 6, 2018

myArray.push and splice

// JavaScript Document

// Creating an array
var myArray = ["Doug", "Mike", "Janet", "Matt"];
console.log(myArray);

// Adding an item to the array
myArray.push("Pat");
console.log(myArray);

// Changing an item in the array
myArray[0] = "Tim";
console.log(myArray);

// Removing items from an array
myArray.splice(1,2);
console.log(myArray);

No comments:

Post a Comment

Remote Hybrid and Office work