check if a variable is array in javascript 1

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
}

Here is what the above code is Doing:
1. We’re creating a variable called myVarToTest and assigning it a value of an array.
2. We’re using the Array.isArray() method to check if myVarToTest is an array.
3. If myVarToTest is an array, we’re printing out a message saying that it is an array.
4. If myVarToTest is not an array, we’re printing out a message saying that it is not an array.

Similar Posts