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.

belongs to collection: Node.js programming Exercises

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)

Write a node.js program to get files or directorie... >>
<< Write a node.js program to replace two or more a&#...