Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does es6 determine whether it is an array?

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report