javascript - 如何在 typescript 中将数组的所有成员初始化为相同的值?

标签 javascript angular typescript

在 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/

相关文章:

javascript - 如何配置服务器部分或前端以避免运行 ng build 时出现未找到 404 错误

javascript - Angular 可以从一个 json 文件中获取数据,但不能从一个单独的文件中获取数据?

JavaScript - 将对象文字作为第二个参数传递给 Object.create()

javascript - 为什么 ng-checked 在页面加载时触发两次

angular - 如何在 Angular 中转义大括号

excel - 从 Excel 任务 Pane 内的 Angular 应用程序读取 Office 加载项 list 文件的设置

javascript - 组合来自多个 javascript block 的代码会导致错误?

javascript - Google Apps 脚本日历服务 : How to store and retrieve CalendarEvents using PropertiesService?

javascript - ngx下拉列表获取选定值

javascript - 如何返回带有内联开关的 jsx 元素?