How to initialize a new array with values in JavaScript
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
I wrote 17 books to help you become a better developer, download them all at $0 cost by joining my newsletter
JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025