Array representation

Viewed 271

i wonder what is the difference of array representation between [] and (3) [Object,Object,Object] ?

i have array of objects like:

var array = [{id: 1, text: 'a'}, {id: 2, text: 'b'}, {id: 3, text: 'c'}];

when i tried to console.log(array) at some line within my codes, sometime it printed as [] and sometime as (3) [Object,Object,Object]. the [] is not empty, though, when i expanded it on browser's console, both contain same values (3 objects).

in my case, when i'm using var array as data for my select2 like this:

$('#elems').select2({
      data: array
});

if, when i console.log(array) and it shows as (3) [Object, Object, Object], the select2 gets the data, and the option would be a,b,c. but, when it shows as [] select2 couldn't read the objects, thus, the option would be empty.

i wonder if select2 reads [] as empty, although on browser's console [] is expandable and contains value. like this:

enter image description here

can anyone explain about this?

2 Answers
Related