I have the following array of objects below (components) and I want to remove all the null entries. How can I go about doing it? I am trying the following:
static deleteNullComponents(components) {
return components.filter(function (el) {
return el['components'] != null;
});
}
but I get the error: TypeError: components.filter is not a function
. How can I fix it?
[
{
"components": [
null,
{
"componentId": "navbar-zJNm0HaP",
"componentIndex": 1,
"componentName": "app-builder-navbar",
},
null,
null,
null,
{
"componentId": "features-MJU8gcYR",
"componentIndex": 5,
"componentName": "app-builder-features",
},
null,
{
"componentId": "features-2hsUdwaT",
"componentIndex": 7,
"componentName": "app-builder-features",
},
null,
{
"componentId": "footer-dLvoLZ16",
"componentIndex": 9,
"componentName": "app-builder-footer",
},
null
],
"name": "Home"
},
{
"components": [
null,
{
"componentId": "navbar-UBdYplVp",
"componentIndex": 1,
"componentName": "app-builder-navbar",
},
null,
{
"componentId": "features-mmEzByeO",
"componentIndex": 3,
"componentName": "app-builder-features"
},
null,
{
"componentId": "features-GZKgh9lV",
"componentIndex": 5,
"componentName": "app-builder-features"
},
null,
{
"componentId": "footer-IyrNODRQ",
"componentIndex": 9,
"componentName": "app-builder-footer",
},
null
],
"name": "About"
}
]