Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to recognize an array in javascript

const array = [1, 2, 3];

Array.isArray(array);  // => true
Array.isArray(object); // => false
Array.isArray(string); // => false
Array.isArray(empty);  // => false

// other ways

({}).toString.call(array);   // => '[object Array]'
({}).toString.call(object);  // => '[object Object]'
({}).toString.call(string);  // => '[object String]'
({}).toString.call(empty);   // => '[object Null]'
Source by dmitripavlutin.com #
 
PREVIOUS NEXT
Tagged: #recognize #array #javascript
ADD COMMENT
Topic
Name
2+3 =