Home > Web Front-end > JS Tutorial > How to use isArray function

How to use isArray function

不言
Release: 2019-02-21 11:02:21
Original
3063 people have browsed it

The Array.isArray() function is used to determine whether the value passed to this function is an array. This function returns true if the passed argument is an array, false otherwise. Let's take a look at the specific use of the isArray function.

How to use isArray function

First let’s take a look at the basic syntax of the isArray function

Array.isArray(obj)
Copy after login

obj is any valid object in How to use isArray function, such as map , list, array, string, etc.

Let’s look at a few specific examples

Example 1:

The code is as follows

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script> 
function func() { 
    document.write(Array.isArray([&#39;Day&#39;,&#39;Night&#39;,&#39;Evening&#39;])); 
} 
func(); 
</script> 
</body>
</html>
Copy after login

The output result is: true

Example 2:

The code is as follows

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script> 
function func() { 
    document.write(Array.isArray({foo: 123})); 
} 
func(); 
</script> 
</body>
</html>
Copy after login

The output result is as follows: false

Example 3:

The code is as follows

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script> 
function func() { 
    document.write(Array.isArray(&#39;foobar&#39;)); 
} 
func(); 
</script>
</body>
</html>
Copy after login

Output The result is: false

This article has ended here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to use isArray function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template