JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow Member

Member operators

Access members of an object.

Description

Member operators allow access to the properties and methods of an object.

  • Under the hood properties and methods are the same thing. A method is a property with a function for it's value.
  • We can use dot or bracket notation to access the members of an object.

Dot Notation

The first way of accessing the members of an object is through dot notation.

Syntax


Signature Description
anObject.propertyGet an object property.
anObject.property = setPropertySet an object property.

Parameters


Parameter Description
propertyA valid JavaScript identifier.
  • Only letters, numbers, the dollar ($) and underscore (_) symbols are allowed.
  • Only letters, the dollar ($) and underscore (_) symbols are allowed as the first character.

Examples

Lets see some examples of using dot notation.




// Store properties in an array.
var dotProps = new Array(6);

dotProps[0] = Object.prototype + '\n'; 
dotProps[1] = Object.constructor + '\n'; 
dotProps[2] = Math.E + '\n'; 
dotProps[3] = Math.PI + '\n'; 
dotProps[4] = Object.toString() + '\n'; 
dotProps[5] = Date.parse(); 

alert(dotProps); 


Press the button below to action the above code:



Bracket Notation

The second way of accessing the members of an object is through bracket notation.

Syntax


Signature Description
anObject[property]Get an object property.
anObject[property] = setPropertySet an object property.

Parameters


Parameter Description
propertyA string that isn't constrained by the naming limitations of dot notation.

Examples

Lets see some examples of using bracket notation.




// Store properties in an array.
var bracketProps = new Array(6);

bracketProps[0] = Object['prototype'] + '\n'; 
bracketProps[1] = Object['constructor'] + '\n'; 
bracketProps[2] = Math['E'] + '\n'; 
bracketProps[3] = Math['PI'] + '\n'; 
bracketProps[4] = Object['toString'] + '\n'; 
bracketProps[5] = Date['parse']; 

alert(bracketProps); 

Press the button below to action the above code:



Related Tutorials

JavaScript Basic Tutorials - Lesson 7 - Objects




  

go to home page Homepage go to top of page Top