javascript - what are the conditions to be a true array -


javascript not have true array. because when tested out thing in google console surprised see there no difference between object , array.

var obj = {}; var arr = [];  typeof obj; //object typeof arr; //object 

i curious know

why so?

and

do javascript possess false array?

and

is typeof wrong , mean not differentiate between object , array?

and

what conditions true array?

thanks!

javascript dynamic language , objects flexible. , there no gurantee that, object have of particular type. because can duck typing.

if want know if object array or not, can use

object.prototype.tostring.call(obj) == '[object array]'; 

this taken underscore.js library's _.isarray function. since popular , used, method should reliable.

if environment supports ecma 5.1, can use array.isarray function, this

array.isarray(obj); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -