var collection = {
2548: {
album: "Slippery When Wet",
artist: "Bon Jovi",
tracks: [
"Let It Rock",
"You Give Love a Bad Name"
]
},
2468: {
album: "1999",
artist: "Prince",
tracks: [
"1999",
"Little Red Corvette"
]
},
1245: {
artist: "Robert Palmer",
tracks: [ ]
},
5439: {
album: "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));
function update(id, prop, value) {
if(prop !== "tracks" && value !== null){
collection[id][prop] = value;
}else if(prop === "tracks" && value !== null){
collection[id][prop].push(value);
}else if(value === null){
delete collection[id]['artist']; //问题在这里!!
}
return collection;
}
console.log(update(5439, "artist", ""));如果我传的第三个参数value为空的话,删除artist这个属性,为什么我这样删除不了??
Suber丶林
Gavin_Alison
慕粉15920169039
老猿
相关分类