Q:

There is a given object, write node.js program to print the given object\'s properties, delete the second property and get length of the object.

0

There is a given object, write node.js program to print the given object's properties, delete the second property and get length of the object.

var user = {
first_name: "John",
last_name: "Smith",
age: "38",
department: "Software"
};

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution

Objects are one of the core workhorses of the JavaScript language, and something you will use all the time. They are an extremely dynamic and flexible data type, and you can add and remove things from them with ease.

var user = {
first_name: "John",
last_name: "Smith",
age: "38",
department: "Software"
};
console.log(user);
console.log(Object.keys(user).length);
delete user.last_name;
console.log(user);
console.log(Object.keys(user).length);

Output of the above code:

{ first_name: 'John',
  last_name: 'Smith',
  age: '38',
  department: 'Software' }
4
{ first_name: 'John', age: '38', department: 'Software' }

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now