From the course: Computer Science Principles Lab: JavaScript

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Changing arrays

Changing arrays - JavaScript Tutorial

From the course: Computer Science Principles Lab: JavaScript

Start my 1-month free trial

Changing arrays

- [Instructor] After you create an array, there are many ways you can change the values and manipulate it using JavaScript. There are three basic functions that are part of any array that you can use to add, change, and remove elements within an array. First, we have an array already created with four elements. If we want to add an element, we can use the push() function. Push() is a function that is part of every array that adds an item to the end of the array. To use it, start with the array name, then add a period, and then add a call to the push() function. Inside of the push() function call, add in the item you want to add to the array. You can add multiple items by separating each with a comma, then send the array to the console to display it. Save and open the webpage in your browser. You'll see that the second array is now displayed and has an additional item inside of it, with the new element that you have pushed onto the end. There is one thing I wanted to point out that…

Contents