[英]Why is push shown as undefined, even though it is a keyword and i have not declared this as any object?
function updateRecords(id, prop, value) {
if (prop !== "tracks" && value !== ""){
collection[id][prop] = value;
}
if (collection[id].hasOwnProperty("tracks") == true){
if (value === ""){
delete collection[id].prop;
}
else{
collection[id].tracks.push(value);
}
}
if (prop === "tracks" && collection[id].hasOwnProperty(prop) == false){
collection.prop = [];
collection[id].prop.push(value);
}
return collection;
}
So the function should add new values to the arrays, but I am not sure why i keep getting an error saying it is push of undefined.所以 function 应该向 arrays 添加新值,但我不知道为什么我一直收到一个错误,说它是未定义的推送。
It seems like you are trying to push something to collection[id].prop
?似乎您正在尝试将某些内容推送到collection[id].prop
?
You must have left out the index reference for collection
at the previous line:您必须在上一行遗漏了collection
的索引参考:
collection[id].prop = [];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.