Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




fill() - FUNCTION


fill() Function


The fill() Function is used to fill the array locations with a specified value.


Let us say we have the below array with four elements.


var x = [5, 8, 2, 9]
JavaScript fill()-Function


And we want to fill 2nd and 3rd location with 100.

JavaScript fill()-Function

Example :



<html>
<body>  
<script>

	var x = [5, 8, 2, 9]
	var y = x.fill(100, 1, 3)
	document.write(y)
	    
</script>      
</body>
</html>


Output :



  5,100,100,9

So, in the above code we have array that has 4 numbers.


var x = [5, 8, 2, 9]
JavaScript fill()-Function


Next, when the fill() Function is called. It accepts 3 arguments.


The first argument is the value to be substituted with i.e. 100.The second argument is the index of the array that should be substituted with the value i.e. 1.The third argument is the last index plus 1 i.e. 3.


var y = x.fill(100, 1, 3)

And we get the below output.

JavaScript fill()-Function