-
Book Overview & Buying
-
Table Of Contents
Learning JavaScript Data Structures and Algorithms - Fourth Edition
By :
So far, you have learned how to add elements in the array. Let's look at how we can remove a value from an array.
To remove a value from the end of an array, we can use the pop method:
numbers.pop(); // number 13 is removed
The pop method also returns the value that is being removed and it returns undefined in case no element is being removed (the array is empty). So, if needed, we can also capture the value that is being returned into a variable or into the console instead:
console.log('Removed element: ', numbers.pop());
The output of our array will be the numbers from -4 to 12 (after removing one number). The length (size) of our array is 17.
The
pushandpopmethods allow an array to emulate a basicstackdata structure, which is the subject of the next chapter.
To manually...
Change the font size
Change margin width
Change background colour