The object and array in javascript sometimes is hard to distinguish. The object is like array and array also like an object.

Object is like array

The properties of object can be accessed with array syntax. The index is the property name:

var obj = { }; = 'Paul';

Here, the brackets syntax is like array access, actually, for objects, the bracket is to set properties for object.

Especially when the property name can not be expressed with dot notation. For example.

obj['special, name'] = 'value';
var s = 'special, name';
obj['load.init'] = 'value';

Array is like object

Since everything in Javascript is object, the array is no exception. Array object extends from Object, thus it has all characteristics of Object.

arr = []; = 'paul';;

Array-like object

With the digital key name and length property, object can act like array:

function msg(m) {
    document.write('<p>'+m + '</p>' + '');
var a = {"0":"a", "1":"b", "2":"c", length:3};  // An array-like object
for ( var i = 0 ; i < a.length; i++ ) {

But it still an object, when you add more properties to the object, the length will not automatically increase.

The String object also array-like and the length changes when string changes.

var s = "hello";
for ( var i = 0 ; i < s.length; i++ ) {
s += "world";
for ( var i = 0 ; i < s.length; i++ ) {


Array is a special object, and other objects may look like or behave like Arrays. But they are not Arrays. Array is a data storage in which the elements retrieved by integral values.

Array itself in its nature is an object, you can set properties for it like any other objects. But its different from set elements. Array also has a set of operations like slice, join that can work directly with Array.