var uniqueProperties = [];
for (var i = 0, length = obj.length; i < length; i++) {
for (var prop in obj[i]) {
if (prop == null || prop == ' ') {
delete obj[i][prop];
}
}
for (var prop in obj[i]) {
if (this.uniqueProperties.indexOf(prop) === -1) {
this.uniqueProperties.push(prop);
}
}
}
I want to first delete the keys with null or blank values, and then add them in the array and check its length.
I think its not getting deleted.
In the first loop, you’re checking to see if “prop” is null or (incorrectly) the empty string, but that doesn’t really make sense. You should be checking the value of that property of “obj[i]”:
Also, your “uniqeProperties” list should also be “assisted” by a separate object so that you can avoid the poor algorithmic performance of repeated linear scans: