Skip to content

Instantly share code, notes, and snippets.

@BiosBoy
Created August 12, 2024 20:21
Show Gist options
  • Save BiosBoy/088105939bcc8104269287bf0d33e0b5 to your computer and use it in GitHub Desktop.
Save BiosBoy/088105939bcc8104269287bf0d33e0b5 to your computer and use it in GitHub Desktop.
const originalArray = [1, 2, 3, 4, 5];
const slicedArray = originalArray.slice(2, 4);
console.log(slicedArray); // [3, 4]
console.log(originalArray); // [1, 2, 3, 4, 5]
const originalArray = [1, 2, 3, 4, 5];
const splicedArray = originalArray.splice(2, 2);
console.log(splicedArray); // [3, 4]
console.log(originalArray); // [1, 2, 5]
const array = [10, 20, 30, 40];
console.log(array.at(-1)); // 40
const array = [1, 2, 3, 4];
const newArray = array.with(2, 99);
console.log(newArray); // [1, 2, 99, 4]
console.log(array); // [1, 2, 3, 4]
const array = [3, 1, 4, 2];
const sortedArray = array.toSorted();
console.log(sortedArray); // [1, 2, 3, 4]
console.log(array); // [3, 1, 4, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment