Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Last active July 10, 2020 15:14
Show Gist options
  • Save sandrabosk/51e940afa42e557d95fffb3f21a8a775 to your computer and use it in GitHub Desktop.
Save sandrabosk/51e940afa42e557d95fffb3f21a8a775 to your computer and use it in GitHub Desktop.
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