What is the difference between `Array.prototype.copyWithin()` and `Array.prototype.fill()`?

JavaScript Professional Medium

JavaScript Professional — Medium

What is the difference between `Array.prototype.copyWithin()` and `Array.prototype.fill()`?

Key points

  • copyWithin() moves elements within the same array
  • fill() replaces elements with a static value in a range
  • Both methods mutate the original array
  • copyWithin() does not change the array length
  • fill() sets elements to a specific value

Ready to go further?

Related questions