Last active
July 10, 2020 15:14
-
-
Save sandrabosk/51e940afa42e557d95fffb3f21a8a775 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const favorites = ['javascript', 'html', 'css']; | |
// remove first element | |
favorites.shift(); | |
console.log(favorites); // => [ 'html', 'css' ] | |
// remove last element | |
favorites.pop(); | |
console.log(favorites); // => [ 'html' ] | |
// add 'react' on the first place | |
favorites.unshift('react'); | |
console.log(favorites); // => [ 'react', 'html' ] | |
// add 'node' to the last place | |
favorites.push('node'); | |
console.log(favorites); // => [ 'react', 'html', 'node' ] | |
// remove element in the position 2 and add 'express' | |
favorites.splice(1, 1, 'express'); | |
console.log(favorites); // => [ 'react', 'express', 'node' ] | |
// remove elements in the positions 2 and 3 and add 'mongodb' | |
favorites.splice(1, 2, 'mongodb'); | |
console.log(favorites); // => [ 'react', 'mongodb' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment