我在obj.Like得到這麼多的對象這刪除JavaScript對象完全
Object {MAILING ADDRESS: "P O BOX 59", APN: "066-102-11-1"}
Object {MAILING ADDRESS: "", APN: ""}
Object {MAILING ADDRESS: "P O BOX 3", APN: "066-105-11-1"}
Object {MAILING ADDRESS: "", APN: ""}
當我申請在它的Null值刪除功能我得到這個
Object {MAILING ADDRESS: "P O BOX 59", APN: "066-102-11-1"}
Object {}
Object {MAILING ADDRESS: "P O BOX 3", APN: "066-105-11-1"}
Object {}
我想完全刪除對象{}並且只想得到2個具有值的對象。 我刪除此值的代碼是
(function filter(obj_field) {
$.each(obj_field, function(key, value) {
if (value === "" || value === null) {
delete obj_field.key;
} else if (Object.prototype.toString.call(value) === '[object Object]') {
filter(value);
} else if ($.isArray(value)) {
$.each(value, function(k, v) {
filter(v);
});
}
});
})(obj_field);
http://stackoverflow.com/questions/742623/deleting-objects-in-javascript的可能的複製 – Sagar
我有點相信你今天早些時候問這樣的事情。但是我要再問一次,你可以舉一個你問題的例子 –
'delete obj_field.key' - 這會刪除對象的關鍵字。使用'delete obj_field'來擺脫整個對象。 –