empty an object javascript code example
Example 1: javascript check if object is empty
function isObjectEmpty(obj) {
return Object.keys(obj).length === 0;
}
Example 2: declare empty object javascript
var objectA = {}
var objectB = new Object()
Example 3: how to initialize empty javascript object
let obj = {};
Example 4: javascript create object empty
var empty_obj = {};
Example 5: js object clear
var props = Object.getOwnPropertyNames(obj);
for (var i = 0; i < props.length; i++) {
delete obj[props[i]];
}
for (var key in obj) {
delete obj[key];
}