Jump to content

Why the dots(.)?


Drycodez

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...