JSFiddle - React, Tailwind, and code Playground

by anish_nair

JavaScript

var a = {}; //Blank Object
var b = {name: 'FirstName', surname: 'LastName'};
var c = new Object(); //Blank Object
var d = [];
d.push('Hello');
d.push('World');

//Note: 'a','c' are blank objects, whereas, 'c' and 'd' are not..

// Pushing all the objects in an array..
var arr = new Array();
arr.push(a,b,c,d);

console.log('arr', arr);

// Looping and checking which objects are empty.. 
for(var i=0; i< arr.length; i++) {
    if(JSON.stringify(arr[i]) !== '{}') {
        console.log('Not Empty', arr[i]);
    } else {
        console.log('Empty', arr[i]);
    }
}

/* Please check the output in the console window.
Press F12 to open the console window. */