在 C 语言中 int myArray[42] = { 0 };在开始时将数组的所有值初始化为 0。我们可以在 typescript 中使用类似的方法吗?
最佳答案
您可以使用 Array.prototype.fill()
The fill() method fills all the elements of an array from a start index to an end index with a static value.
var arr = new Array(30);
arr.fill(0); // Fills all elements of array with 0
关于javascript - 如何在 typescript 中将数组的所有成员初始化为相同的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38959023/