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.

Example

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

<!DOCTYPE html>
<html>
   <body>
      <script>
         var num = ["One", "Two", "Three", "Four", "Five"];
         document.write(num);

         document.write("<br>"+num.fill("Six",2,3));
      </script>
   </body>
</html>
Updated on: 2020-03-02T06:40:47+05:30

124 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements