To check whether variable array or not need to use type check syntax: instanceof:
[] instanceof Array // true 'string' instanceof Array // false |
You can make a function to incapsulate the feature:
function is_array(variable) { return variable instanceof Array } |
Using:
is_array([]) // true is_array('string') // false |
jQuery also has the similar function:
$.isArray([]) // true $.isArray('string') |
Books to read
|
|
|