Jump to content

Why the dots(.)?


Drycodez
 Share

Recommended Posts

It sometimes helps to think about something you already know. Lets construct a typical array:

var myArray = new Array();myArray[0] = "Kim";myArray[1] = "Mary";myArray[2] = "Heinrich";

The array is numerically indexed. The identifier that goes inside the [brackets] is a number.The next array is an associative array. The indexes are strings instead of numbers.

var myArray = new Array();myArray['car'] = "Honda";myArray['city'] = "London";myArray['country'] = "UK";

A lot of people do not realize that you can access an array element using dot notation. The following are equivalent:

myArray['car']myArray.car

The relationship between index notation and dot notation is true for ALL objects, not just arrays. In your example, the following are equivalent:

document.getElementByIddocument['getElementById']

I hope that helps a little.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...