Categories JavaScript Answers How to set all values of an array with JavaScript? Post author By John Au-Yeung Post date October 15, 2022 No Comments on How to set all values of an array with JavaScript? Spread the love To set all values of an array with JavaScript, we use the fill method. For instance, we write const arr = new Array(3).fill(9); to create an empty array with length 3 with Array(3). Then we call fill with 9 to fill the empty slots with 9’s. Related Posts How to remove empty array values from an array with JavaScript?Sometimes, we want to remove empty array values from an array with JavaScript. In this… How to set default array values with JavaScript?To set default array values with JavaScript, we call the fill method. For instance, we… How to add default array values with JavaScript?To add default array values with JavaScript, we call the fill method. For instance, we… By John Au-Yeung Web developer specializing in React, Vue, and front end development. View Archive → ← How to slice an object in JavaScript? → How to use reduce() to find min and max values with JavaScript? Leave a Reply Cancel replyYour email address will not be published. Required fields are marked *Comment * Name * Email * Website Save my name, email, and website in this browser for the next time I comment. Current ye@r * Leave this field empty