What is the usage of fill() method in JavaScript?

The fill() method in JavaScript is used to fill elements with static value in an array. The following are the parameters for fill() −

  • value− The value to be filled.
  • begin− The start index to begin filling the array.
  • end− The ending index to stop filling the array.


You can try to run the following code to learn how to work with fill() method on JavaScript −

<!DOCTYPE html>
         var num = ["One", "Two", "Three", "Four", "Five"];