javascript - 具有对象数组的对象

标签 javascript arrays object

我正在尝试创建一个包含 JavaScript 中的对象数组的对象

var alertArray = {
    {threshold: 'critical', deviceName: 'Device Agg-02-01', text: 'CPU exceeding policy threshold of 80%', time: '7:00 PM'},
    {threshold: 'critical', deviceName: 'Device Leaf-12-22', text: 'Memory utilization exceeding 40%', time: '6:34 PM'},
    {threshold: 'warning', deviceName: 'Leaf10-12', text: 'New Software available for upgrade on device', time: '5:10 PM'},
    {threshold: 'warning', deviceName: 'Leaf10-11', text: 'New Software available for upgrade on device', time: '4:32 PM'}
};

我不明白我做错了什么,请帮助

最佳答案

你忘记了数组部分:

var alertArray = {
    someArray: [{threshold: 'critical', deviceName: 'Device Agg-02-01', text: 'CPU exceeding policy threshold of 80%', time: '7:00 PM'},
    {threshold: 'critical', deviceName: 'Device Leaf-12-22', text: 'Memory utilization exceeding 40%', time: '6:34 PM'},
    {threshold: 'warning', deviceName: 'Leaf10-12', text: 'New Software available for upgrade on device', time: '5:10 PM'},
    {threshold: 'warning', deviceName: 'Leaf10-11', text: 'New Software available for upgrade on device', time: '4:32 PM'}]
};

关于javascript - 具有对象数组的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37565216/

相关文章:

Javascript:按值过滤对象并返回新对象(不是数组)

javascript - 使用 Javascript 将预定义字符串添加到使用表单的用户输入

arrays - 为什么最大和子数组是暴力 O(n^2)?

javascript - 通过循环构建 JSON 数组

javascript - Mootools 1.6 子类初始化方法未被调用

javascript - 如何让 Knockout.js 为属性设置 namespaceURI?

java - java中多维数组内存分配不足

c# - 如何在 C# 中将对象数组向上转换为另一种类型的对象数组?

JavaScript 对象 - 构造后对象值未定义

C++ 读写同一个类的多个对象