Home > Article > Web Front-end > How to use isArray function
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.
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(['Day','Night','Evening'])); } 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('foobar')); } 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!