Get the App
SLTechnology News&Howtos  ›  Development  › 

How can javascript tell if it is an array?

Shulou Source: shulou.com Published: 2022-06-02 01:45:02 09月15日 Update

This article mainly introduces the relevant knowledge of "how to identify whether javascript is an array". The editor shows you the operation process through an actual case. The operation method is simple and fast, and it is practical. I hope this article "how to identify javascript is an array" can help you solve the problem.

Javascript identifies an array of methods: 1, using the instanceof operator, syntax "variable name instanceof Array"; 2, using the isArray () method, syntax "Array.isArray (variable name)".

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

Javascript identifies whether it is an array

Method 1: use the instanceof operator

Var cars=new Array (); cars [0] = "Saab"; cars [1] = "Volvo"; cars [2] = "BMW"; / / determine whether the method if (cars instanceof Array) {[xss_clean] ("is an array") is supported. ;}

Method 2: use the isArray method

Var cars=new Array (); cars [0] = "Saab"; cars [1] = "Volvo"; cars [2] = "BMW"; / / determine whether the method if (Array.isArray) {if (Array.isArray (cars)) {[xss_clean] ("the object is an array") is supported. ;}} this is the end of the introduction to "how javascript recognizes whether it is an array". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Methods arrays knowledge variables operators industry syntax support different practical content practical practical objects tutorials articles more cases environments computers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB Shulou Information Apple Shulou Technology