Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created July 14, 2024 18:01
Show Gist options
  • Save prof3ssorSt3v3/30018890d5876cbc8771935f7d62fb22 to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/30018890d5876cbc8771935f7d62fb22 to your computer and use it in GitHub Desktop.
Code from tutorial on Array with and copyWithin methods
//copy = Array.prototype.with(index, value)
//changed = Array.prototype.copyWithin(index, start, end)
const names = ['Bob', 'Louise', 'Gene', 'Linda', 'Teddy'];
const newNames = names.with(1, 'Gayle'); // names[1] = 'Gayle'
console.log(names);
console.log(newNames);
console.log(names == newNames); //false
console.log(names === newNames); //false
const changed = names.copyWithin(1, 2, 3);
console.log(names === changed);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment