I have a javascript object (I actually get the data through an ajax request):
(我有一个javascript对象(我实际上通过ajax请求获取数据):)
var data = {};
I have added some stuff into it:
(我添加了一些东西:)
data[0] = { "ID": "1"; "Status": "Valid" }
data[1] = { "ID": "2"; "Status": "Invalid" }
Now I want to remove all objects with an invalid status (but keep everything the ordering same):
(现在我想删除状态无效的所有对象(但保持所有顺序相同):)
var tempData = {};
for ( var index in data ) {
if ( data[index].Status == "Valid" ) {
tempData.push( data );
}
}
data = tempData;
In my mind, all of this should work, but I am getting an error that tempData.push
is not a function.
(在我看来,所有这一切都应该工作,但我收到一个错误, tempData.push
不是一个函数。)
I understand why it isn't the same as an array, but what could I do otherwise?(我理解为什么它与数组不一样,但我能做什么呢?)
ask by Andrew Jackman translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…