create new object in javascript code example

Example 1: object inside object javascript

var obj = {
  prop1: 5,
  obj2: {
    prop1: [3, 6, 3],
    prop2: 74,
    prop3: {
      str: "Hello World"
    }
  }
};

console.log(obj.obj2.prop3.str); //output: "Hello World"

Example 2: creating an object javascript

let obj = {
// fields
  name:"value",
  num: 123,
//methods
  foo: function(){}
  
}

Example 3: how to create object js

function person(fname, lname, age, eyecolor){
  this.firstname = fname;
  this.lastname = lname;
  this.age = age;
  this.eyecolor = eyecolor;
}

myFather = new person("John", "Doe", 50, "blue");
document.write(myFather.firstname + " is " + myFather.age + " years old.");

Example 4: create object javascript

const object = {
  something: "something";
}

Example 5: js create object with properties

var mycar = new Car('Eagle', 'Talon TSi', 1993);

Example 6: javascript construct new object

person = new Object();