Accessing Property Values

By: Dusty Arlia
Published on Monday, June 10, 2013, 02:32 PM
Last Updated on Friday, July 03, 2015 at 3:30 PM
Total Updates: 3

There are two ways to access property values:

  • Using dot-syntax
  • Including the property name in brackets

Using dot-syntax is more common and slightly more readable. Here is an example of dot-syntax:

//object declaration and initialization
var employee = {
    "first_name": "Justin",
    "last_name": "Bieber"
};

//Accessing the first_name and last_name
//properties using dot-syntax
employee.first_name;  //Justin
employee.last_name;   //Bieber

Here is an example using brackets to access property values.

employee["first_name"]; //Justin
employee["last_name"];  //Bieber

Comments:

Ad: