Get the App
SLTechnology News&Howtos  ›  Development  › 

How does es6 determine whether it is an array?

Shulou Source: shulou.com Published: 2022-05-31 18:39:51 09月22日 Update

This article mainly explains "how to judge whether es6 is an array". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to determine whether es6 is an array or not.

In es6, you can use the "Array.isArray ()" method to determine whether the object is an array. If the object is an array, the result is true. If the object is not an array, the result is false, and the syntax is "Array.isArray (js object to be detected)".

This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.

How can es6 tell if it is an array?

In the program to judge the array is a very common application, but in ES5 can not strictly judge whether the JS object is an array, there will be some problems, the more widely recognized is to judge with the help of toString, which is obviously not very concise.

ES6 provides the Array.isArray () method to more succinctly determine whether the JS object is an array.

Determines the JS object. If the value is Array, it is true;, otherwise it is false.

Syntax use:

Array.isArray (obj)

JS objects to be detected by obj

Examples are as follows:

Take an example of how Array.isArray () determines an array.

/ / the following function calls all return trueArray.isArray ([]); Array.isArray ([10]); Array.isArray (new Array ()); Array.isArray (new Array ('ajar,' baked,'c')) / / little-known fact: Array.prototype is also an array. All the following function calls return falseArray.isArray (); Array.isArray ({}); Array.isArray (null); Array.isArray (undefined); Array.isArray (17); Array.isArray ('Array'); Array.isArray (true); Array.isArray (false); Array.isArray (new Uint8Array (32)) Array.isArray ({_ proto__: Array.prototype}) At this point, I believe you have a deeper understanding of "how to judge whether es6 is an array". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Arrays objects methods simplicity content functions examples results grammar facets learning detection practicality deeper facts interests practicality practicality common simple operation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn Shulou Technology macOS MariaDB