Get the App
SLTechnology News&Howtos  ›  Development  › 

How does es6 determine whether the array is empty?

Shulou Source: shulou.com Published: 2022-06-01 06:37:23 09月27日 Update

This article mainly explains "how to determine whether the array is empty by es6". 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 the array is empty by es6".

Es6 method to determine whether the array is empty: 1, use the "arr.length = = 0" statement to determine whether the length of the array is 0, if it is 0, it is empty; 2, use the "JSON.stringify (arr) ='[]'" statement, if the return value is false, it is empty.

The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.

The method of judging whether the array is empty by es6

Method 1: use the length attribute

Let arr = []; if (arr.length = = 0) {console.log ("array is empty")} else {console.log ("array is not empty")}

Method 2: using JSON.stringify ()

Let arr = [1 arr 2]; if (JSON.stringify (arr) = ='[]') {console.log ("array is empty")} else {console.log ("array is not empty")}

At this point, I believe you have a deeper understanding of "how es6 determines whether the array is empty". 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 methods content statements learning practical deeper interest practicality properties easy to operate tutorials more friends environment computers systems websites length Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology macOS OPPO Reno Shulou Information Huawei