object create in javascript code example

Example 1: create nodejs new object

const personFactory = (firstName, lastName, email) => {
    return {
        firstName: firstName,
        lastName: lastName,
        email: email,
        info() {
            return `${this.firstName} ${this.lastName}, ${this.email}`;
        }
    };
};

let person = personFactory('John', 'Doe', '[email protected]');

console.log(person.info());

Example 2: creating an object javascript

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

Example 3: objects in javascript

let object = {
  'key1': 'value1',
  'key2': 'value2',
  'keyn': 'valuen',
};
console.log(object);

Example 4: create object javascript

const object = {
  something: "something";
}

Example 5: objects in javascript

var object = {'key':'value','the value can be anything',[1,null,'Dr.Hippo']};

Example 6: javascript construct new object

person = new Object();

Tags:

Java Example