Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

check if a variable is array in javascript

// inside if else check
if(Array.isArray(myVarToTest)) {
	// myVatToTest is an array
} else {
	// myVarToTest is not an array
}
Comment

check if element is array javascript

Array.isArray([]) //true
Array.isArray({}) //false
Array.isArray('') //false
Array.isArray(null) //false
Comment

js check if a variable is an array

let fruit = 'apple';
let fruits = ["apple", "banana", "mango", "orange", "grapes"];

const isArray = (arr) => Array.isArray(arr);

console.log(isArray.(fruit)); //output - false
console.log(isArray.(fruits)); //output- true
Comment

how to check if something is array javascript


function isArray(value) {
    return Object.prototype.toString.call(value) === "[object Array]";
}
Comment

Check if value is array

Method 1: Using the isArray method
Array.isArray(variableName)'

Method 2:
variable instanceof Array

Method 3:
variable.constructor === Array
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery check if field exist by name 
Javascript :: can you use javascript split with more than one separator 
Javascript :: track window resize in vue 
Javascript :: angular input press enter 
Javascript :: connect mongoose to atlas 
Javascript :: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. 
Javascript :: regex get only domain name from url 
Javascript :: javascript stop setinterval 
Javascript :: how to submit using checkbox 
Javascript :: generate random date in javascript 
Javascript :: add jquery to project 
Javascript :: google sheets get sheet by name 
Javascript :: node js list all installed modules 
Javascript :: moment format date dd/mm/yyyy 
Javascript :: console.log object object 
Javascript :: jquery ajax get 
Javascript :: jquery form serialized data 
Javascript :: for of get index 
Javascript :: js change video src 
Javascript :: how to connect frontend with solidity 
Javascript :: increase font size chartjs 
Javascript :: javascript remove get parameter from url 
Javascript :: how to get a random element of an array javascript 
Javascript :: Javascript function to get the difference between two numbers 
Javascript :: javascript innerhtml table 
Javascript :: find min value in array javascript 
Javascript :: check jquery version in chrome 
Javascript :: get child element by class javascript 
Javascript :: discord javascript error cannot find module 
Javascript :: text to speech js 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =