how to create object with key and value javascript code example

Example 1: javascript create object key from variable

//For ES6 and Babel
{
    [yourKeyVariable]: "yourValue",
}

// ES5 Alternative
// Create the object first, then use [] to set your variable as a key
var yourObject = {};

yourObject[yourKeyVariable] = "yourValue";

Example 2: js create object with properties

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

Example 3: js create object with properties

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