gpt4 book ai didi

javascript - 如何将数据推送到带有键和值的数组中?

转载 作者:行者123 更新时间:2023-12-03 01:55:58 25 4
gpt4 key购买 nike

我有这个带有数组的对象

$scope.filters = {     
Sites: [],
Regions: [],
Devices : [],
Variables : [],
};

我想插入变量 {'VariableName': 'Total Active Energy'};

我做到了

     var obj = {};
obj['VariableName'] = response.data[0].AutoReportVariable;
$scope.filters.Variables.push(obj);
console.log($scope.filters.Variables);

但在控制台我采取:

0:{VariableName:'Total Active Energy'}
how can i push the value to take in console only {VariableName:'Total Active Energy'} without key 0 ?

我想要这个

$scope.filters = {     
Sites: [],
Regions: [],
Devices : [],
Variables : [{VariableName:'Total Active Energy'}]
};

最佳答案

不是这样的,

$scope.filters = {     
Sites: [],
Regions: [],
Devices : [],
Variables : [],
};
$scope.filters.Variables.push({
VariableName: 'Total Active Energy'
});
console.log($scope.filters.Variables);

关于javascript - 如何将数据推送到带有键和值的数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50228622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com