Answers for "js how to test if value is array"

1

js test if array

if(Array.isArray(myVarToTest)) {
	// myVatToTest is an array
} else {
	// myVarToTest is not an array
}
Posted by: Guest on September-02-2020
0

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]'
Posted by: Guest on November-25-2020

Code answers related to "js how to test if value is array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language