I have an JSONarray which looks like this,
{
"TotalMemory": [{
"key": "TotalMemory",
"values": [
[118, 10]
]
}],
"Freememory": [{
"key": "Freememory",
"values": [
[121, 10]
]
}],
"BufferSize": [{
"key": "BufferSize",
"values": [
[123, 10]
]
}],
"TotalSwapMemory": [{
"key": "TotalSwapMemory",
"values": [
[125, 10]
]
}],
"UsedSwapMemory": [{
"key": "UsedSwapMemory",
"values": [
[127, 10]
]
}],
"FeeSwapMemory": [{
"key": "FeeSwapMemory",
"values": [
[129, 10]
]
}],
"": [{
"key": "",
"values": []
}]
}
i need to remove the last item which is empty there. I have followed Remove empty , but this does not work.
$scope.displayData = $scope.displayData.filter(function() { return true; });
console.log(angular.toJson($scope.displayData));
You can use Object.keys and delete, like so
Object.keys($scope.displayData).forEach(function(key) {
if (!key) {
delete $scope.displayData[key];
}
});
$scope.displayData is Object, .filter is Array method, in Object there is no .filter method
Your structure is not an Array, it is an Object with keys (properties) and values.
To remove the empty item, you can simply use delete:
delete $scope.displayData[""];
This will not error if $scope.displayData[""] does not exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With