Array.from, Array.of and fill
Array.from builds arrays from iterables or length objects with a map function. Array.of creates from arguments and fill sets values.
Example
console.log(Array.from("abc"), Array.from({ length: 3 }, (_, i) => i * 2));
console.log(Array.of(7), new Array(3).fill(0));
console.log([...Array(3).keys()]);Exercise
Make an array of 5 zeros.
new Array(5).(0)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.