Home  >  Article  >  Web Front-end  >  How to use isArray function

How to use isArray function

不言
不言Original
2019-02-21 11:02:213022browse

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)

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>

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>

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>

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!

Statement:
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