The JavaScript array fill() method is used to fill elements into an array with static values.
Syntax:
array.fill (value, start, end)
Parameters:
value: It represents static value which have to be filled. It is required.
start: It represents the index from where the value starts filling. Default is 0. It is optional.
end: It represents the index where the value stops filling. Default is array.size-1. It is optional.
Returns:
Modified Array.
Example:
<!DOCTYPE html> <html> <head> </head> <body> <script> var a = ["GOLD","SILVER","DIAMOND","RUBY","PLATINUM"] var result=a.fill("BRONZE",1,4); document.writeln(a); </script> </body> </html> |
Output:
GOLD,BRONZE,BRONZE,BRONZE,PLATINUM |
Please Share