I am currently working with an array of objects and have the need to remove any empty properties within the objects.
For instance:
var quotes = [
{
quote: "Bolshevism is not a policy; it is a disease. It is not a creed; it is a pestilence.",
source: "Winston Churchill",
citation: "",
year: "29 May 1919",
place: ""
},
{
quote: "Learn while you live",
source: "",
citation: "X",
year: "1950",
place: ""
}];
I have multiple objects like these with randomly empty properties.
What I want to achieve is to display only the properties that are not empty on the page.
My approach involves looping through the objects to identify and remove the empty properties using indexOf() and splice():
function findEmptyProp(quotes) {
for (prop in quotes) {
if(quotes[i].children === '') {
return indexOf(quotes[i]);
quotes.splice(i, 1);
}}}
Any assistance would be greatly appreciated.