How to Create an Object in JavaScript

***If this post helped you, please support this blog by clicking one of the links on this page. Thanks :) ***

An object can easily be created in JavaScript by creating a new instance of the native JavaScript Object class. Following this, properties can be assigned to it, as follows:

var objCar = new Object();
objCar.wheels = 4;

document.write(objCar.wheels);

One Response to “How to Create an Object in JavaScript”

  1. Asanka Says:

    I found this method to be easier

    var o = {};
    o.prop = 'val';

    and for arrays var a = [];

Leave a Reply