I have the following JavaScript object:
var items = [
{
item1: '',
item2: 'foo'
},
{
item1: 'bar'
item2: ''
}
];
I'd like to remove all key/value pairs where the value is either empty or null. The following doesn't appear to be working as intended:
$.each(items, function(i,v){
$.each(items[i], function(i2, v2){
if (v2 === "" || v2 === null){
delete items[i2];
}
});
});
console.log(items);
Console log returns the following error: Uncaught TypeError: Cannot read property 'length' of undefined.
How do I get this work correctly?