Animations
API
Arrays
Async
Basics
Challenges
Classes
Console
Dates
Debugging
DOM Elements
DOM Methods
DOM Properties
Event Listeners
Flow Control
Forms
Functions
Global Functions
JSON
Keywords
Libraries (3rd party)
Math
Modules
Objects
Snippets
String
Types
Widgets
Window Object
https://www.w3schools.com/jsref/jsref_obj_array.asp
The fill()
method fills the specified elements in an array with a static value.
You can specify the position of where to start and end the filling. If not specified, all elements will be filled.
array.fill(value, optional: start, optional: end)
https://www.w3schools.com/jsref/jsref_fill.asp
let fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.fill("Pineapple");
document.getElementById("demo1").innerHTML = fruits.toString();
Here's an example where we specify the array elements to be replaced
Here's an example using a function expression. Instead of creating a separate function, were defining its definition right in the filter's argument.
let names = ["Anna", "Barbara", "Cathy", "Denise", "Esther", "Frances"];
names.fill("Ricky Bobby", 2,4);
document.getElementById("demo2").innerHTML = fruits.toString();