js object define code example

Example 1: js object

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

Example 2: object object javascript

person = {
    'name':'john smith'
    'age':41
};

console.log(person);
//this will return [object Object]
//use
console.log(JSON.stringify(person));
//instead

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: js create object with properties

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

Example 5: js create object with properties

function Car(make, model, year) {
  this.make = make;
  this.model = model;
  this.year = year;
}

Example 6: objects in javascript

let name = {
	name1: 'mark'
}

Tags:

Java Example