js test if array
if(Array.isArray(myVarToTest)) {
// myVatToTest is an array
} else {
// myVarToTest is not an array
}// If you want to test if a variable (object) is an instance of
// an array. You can use the Array.isArray(varName) method
// this method takes one argument, the variable or object you want to test
// and returns true, if the argument is an array
// or false, if the argument is not an array
if (Array.isArray(object)) {
// is true
} else {
// is false
}
Array.isArray([1, 2, 3, 4]); // Returns true
Array.isArray(4); // returns false
// this could be used for flattening an array of arrays
Also in JavaScript:
- javascript months array
- javascript merge two array with spread operator
- what are callbacks
- how to send authorization in header of HTTP GET using ajax
- define a media query in styled components
- javascript async script
- how create array with names of files in folder nodejs
- read and save excel with react
- does string contain special charactors javascript
- for javascript delay
- javascript find
- npm react-router-dom
- jquery add element array
- href javascript void
- how to convert a number to a string in javascript
- number format reactjs
- bearer token header
- regular expression not to allow space in javascript
- react select
- scroll down up js
- resizable in jquery interaction
- javascript add div to body with class
- electron quit app from renderer
- push item to array js