当我将数组的内容推送到另一个数组时
"未捕获的TypeError:在此代码段中无法读取未定义的属性'push'错误.
var order = new Object(), stack = [];
for(var i=0;i<a.length;i++){
if(parseInt(a[i].daysleft) == 0){ order[0].push(a[i]); }
if(parseInt(a[i].daysleft) > 0){ order[1].push(a[i]); }
if(parseInt(a[i].daysleft) < 0){ order[2].push(a[i]); }
}
Run Code Online (Sandbox Code Playgroud)
为什么我在第二个if语句中出现此错误?非常感谢!
在JSLint中,它警告说
var x = new Array();
Run Code Online (Sandbox Code Playgroud)
(这不是一个真正的变量名称)应该是
var result = [];
Run Code Online (Sandbox Code Playgroud)
第一种语法有什么问题?这个建议背后的原因是什么?
在普通对象中,我们可以推送到普通数组值,如 obj.l =[]; obj.l.push("测试")
例子。
var prxy = new Proxy({} , {
get(target, name){
return target[name]
},
set(target,name, value){
target[name] = value;
return true;
}
})
prxy.h = {test : "test"}
>> {test: "test"}
prxy.h
>>{test: "test"}
prxy.h.push("test")
>>VM2724:1 Uncaught TypeError: prxy.h.push is not a function
at <anonymous>:1:8
Run Code Online (Sandbox Code Playgroud)