Adding New Properties in object in javascript

 You can add new properties to an existing object by simply giving it a value.

Assume that the person object already exists - you can then give it new properties:

const person = {

  firstname: "John",

  lastname: "Doe",

  age: 50,

  eyecolor: "blue"

};



person.nationality = "English";

console.log(person);

// output
{ firstname: 'John',
  lastname: 'Doe',
  age: 50,
  eyecolor: 'blue',
  nationality: 'English' }

Comments

Popular posts from this blog

Two Sum II - Input Array Is Sorted

Comparable Vs. Comparator in Java

Increasing Triplet Subsequence