Home  >  Article  >  Operation and Maintenance  >  How Javascript fills an array with data

How Javascript fills an array with data

WBOY
WBOYforward
2023-05-13 17:10:141297browse

Fill the array with data

If we need to fill the array with some data, or need a data with the same value, we can use the fill() method.

var plants = new Array(8).fill('8');
console.log(plants); // ['8', '8', '8','8', '8', '8','8', '8']

The above is the detailed content of How Javascript fills an array with data. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete