How to initialize a new array with values in JavaScript
New Courses Coming Soon
Join the waiting lists
Find out how you can initialize a new array with a set of values in JavaScript
Simple solution:
Array(12).fill(0)
fill()
is a new method introduced in ES6.
→ Get my JavaScript Beginner's Handbook
→ Read my
JavaScript Tutorials
on The Valley of Code
→ Read my
TypeScript Tutorial
on The Valley of Code
Here is how can I help you:
- COURSES where I teach everything I know
- CODING BOOTCAMP cohort course - next edition in 2025
- BOOKS 16 coding ebooks you can download for free on JS Python C PHP and lots more
- Follow me on X