Javascript Object Use object As Arrays

Description

Javascript Object Use object As Arrays



let myObject = { property1:234 };

// We can access the property using dot notation:
console.log( myObject.property1 );   /*from www  .j  a v a2 s.c  o m*/

// We can also access it using array notation:
console.log( myObject["property1"]);   

myObject["newProperty"] = "Hello World";

myObject["myFunction"] = function() { 
     console.log("It worked!"); 
};

myObject["myFunction"]();  

myObject.myFunction();  



PreviousNext

Related