Array.isArray()
MethodYou can use the JavaScript Array.isArray()
method to check whether an object (or a variable) is an array or not. This method returns true
if the value is an array; otherwise returns false
.
Let's check out the following example to understand how it works:
<script>
// Creating some variables
var v1 = {name: "John", age: 18};
var v2 = ["red", "green", "blue", "yellow"];
var v3 = [1, 2, 3, 4, 5];
var v4 = null;
// Testing the variables data type
typeof(v1); // Returns: "object"
typeof(v2); // Returns: "object"
typeof(v3); // Returns: "object"
typeof(v3); // Returns: "object"
// Testing if the variable is an array
Array.isArray(v1); // Returns: false
Array.isArray(v2); // Returns: true
Array.isArray(v3); // Returns: true
Array.isArray(v4); // Returns: false
</script>
The Array.isArray()
method is supported in all major browsers, such as Chrome, Firefox, IE (9 and above)
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on harsukh21@gmail.com
How to assign block of HTML code to a JavaScript variable
Use the concatenation operator (+) Th...How to get current image size (width & height) in javascript
Use the JavaScript clientWidth ...onClick event Handling in React with Example
In this tutorial, we are going to look a...How to remove URL or Route From CSRF Protection
Hello Friend, In laravel sometime we...How to Update the Node Version in Ubuntu
In this article i will share with you ho...