July 13, 2023
Program to use JavaScript Array fill() method
let a = ["JavaScript","Python","Php","Css","Html"];
let b = a.fill("Java");
console.log(b);
Output
[ 'Java', 'Java', 'Java', 'Java', 'Java' ]
Steps Description
- Declare two variable
a
andb
- Initialize two variable with value of array
a = ["JavaScript","Python","Php","Css","Html"]
andb = a.fill("Java")
- Array
fill()
method fills the elements of the array with the given value. - The value of
b
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript Array fill() method
let c = ["JavaScript","Python","Php","Css","Html"];
let d = c.fill("Java",1,3);
console.log(d);
Output
[ 'JavaScript', 'Java', 'Java', 'Css', 'Html' ]
Steps Description
- Declare two variable
c
andd
- Initialize two variable with value of array
c = ["JavaScript","Python","Php","Css","Html"]
andd = c.fill("Java",1,3)
- Array
fill()
method fills the elements of the array with the given value. - The value of
d
variable is displayed with the help of console.log inbuilt function
by : Suhel Akhtar
Quick Summary:
JavaScript Array fill() method