Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

How to determining whether a passed value is an Array in JavaScript

1 Answer

0 votes
document.write("Array.isArray([]) = " + Array.isArray([]) + "<br />");
document.write("Array.isArray([1]) = " + Array.isArray([1]) + "<br />");
document.write("Array.isArray(new Array()) = " + Array.isArray(new Array()) + "<br />");
document.write("Array.isArray(Array.prototype) = " + Array.isArray(Array.prototype) + "<br />");
document.write("Array.isArray() = " + Array.isArray() + "<br />");
document.write("Array.isArray({}) = " + Array.isArray({}) + "<br />");
document.write("Array.isArray(null) = " + Array.isArray(null) + "<br />");
document.write("Array.isArray(100) = " + Array.isArray(100) + "<br />");
document.write("Array.isArray(undefined) = " + Array.isArray(undefined) + "<br />");
document.write("Array.isArray('Array') = " + Array.isArray('Array') + "<br />");
document.write("Array.isArray(true) = " + Array.isArray(true) + "<br />");
document.write("Array.isArray(false) = " + Array.isArray(false) + "<br />");

var arr = ['a', 'b', 'c', 'd', 'e'];
document.write("Array.isArray(arr) = " + Array.isArray(arr) + "<br />");

var n = 9;
document.write("Array.isArray(n) = " + Array.isArray(n) + "<br />");

 
/*
run

Array.isArray([]) = true
Array.isArray([1]) = true
Array.isArray(new Array()) = true
Array.isArray(Array.prototype) = true
Array.isArray() = false
Array.isArray({}) = false
Array.isArray(null) = false
Array.isArray(100) = false
Array.isArray(undefined) = false
Array.isArray('Array') = false
Array.isArray(true) = false
Array.isArray(false) = false
Array.isArray(arr) = true
Array.isArray(n) = false
 
*/

 



answered Jul 30, 2016 by avibootz
...