Remove element from JSON Object

To iterate through the keys of an object, use a for .. in loop:

for (var key in json_obj) {
    if (json_obj.hasOwnProperty(key)) {
        // do something with `key'
    }
}

To test all elements for empty children, you can use a recursive approach: iterate through all elements and recursively test their children too.

Removing a property of an object can be done by using the delete keyword:

var someObj = {
    "one": 123,
    "two": 345
};
var key = "one";
delete someObj[key];
console.log(someObj); // prints { "two": 345 }

Documentation:

  • https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Working_with_Objects
  • https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/for…in
  • https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/delete

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)