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
Post a Comment