create js object code example

Example 1: js object

let car = {
  		name: "BMW",
  		colour: "black",
  		year: "2020",
  		owner: {
		names = ["Andy" , "Steve" , "Tony" ]
		}
};

Example 2: objects in javascript

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

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: how to create a object in javascript

var a = {
name: "aakash",
  age:30
}

Example 6: how to create an object in javascript

const person = {
  name: 'Anthony',
  age: 32,
  city: 'Los Angeles',
  occupation: 'Software Developer',
  skills: ['React','JavaScript','HTML','CSS']
};

//Use Template Literal to also log a message to the console
const message = `Hi, I'm ${person.name}. I live in ${person.city}.`;
console.log(message);

Tags:

Java Example