Last active
July 4, 2020 15:59
-
-
Save erockdotdev/e156b7cf2d9e73c0ac1ef19064316fdc to your computer and use it in GitHub Desktop.
This file contains 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
VS code change es-lint settings | |
https://bit.ly/3g6Lwde | |
CTRL + SHIFT + P, type workspace settings (JSON) and press ENTER. | |
Slice vs Splice | |
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
slice // immutable ( does not mutate original array ) | |
const sliceArr = numbers.slice(1, 5); | |
console.log(numbers); // [1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
console.log(sliceArr); // [2, 3, 4, 5]; | |
splice // mutable ( does mutate original array ) | |
const spliceArr = numbers.splice(1, 5); | |
console.log(numbers); // [1, 7, 8, 9]; | |
console.log(spliceArr); // [2, 3, 4, 5, 6]; | |
add item to middle of array | |
const addWord = [...numbers.slice(0, 3), "STUFF", ...numbers.slice(3)]; | |
console.log(addWord); // [1, 2, 3, "STUFF", 4, 5, 6, 7, 8, 9] | |
remove item in middle of array | |
const removeNumber5 = [...numbers.slice(0, 4), ...numbers.slice(5)]; | |
console.log(removeNumber5); // [1, 2, 3, 4, 6, 7, 8, 9] | |
More Array methods and related Object methods to review | |
Array.from() Array.isArray() | |
.join() .pop() .push() .shift() .unshift() [...spread] .flatten() | |
.slice() .splice() .indexOf() .reverse() .includes() .find() | |
.filter() .some() .every() .sort() | |
Object.entries() Object.keys() Object.values() Object.fromEntries() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment