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>