In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how es6 judges whether there are values in the array, the content is detailed and easy to understand, the operation is simple and fast, and it has certain reference value. I believe everyone will have some gains after reading this es6 article on how to judge whether there are values in the array. Let's take a look at it together.
Two methods: 1, get the array length, determine whether the length is 0, syntax "arr.length==0", if 0 then there is no value in the array. 2. Convert the array to a JSON string, determine whether the string is "[]", syntax "JSON.stringify(arr)=='[]'", if so, there is no value in the array.
Operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.
ES6 determines whether there is a value in the array, that is, whether the array is empty. Here are two ways to judge.
Method 1: Use the length attribute
Use the length attribute to get the array length and determine whether the array length is 0.
If 0, there are no values in the array.
If it is not 0, there is a value in the array.
let arr = [1];if (arr.length == 0){ console.log("No values in array");}else { console.log("array has values");}console.log(arr);
Method 2: Use JSON.stringify()
The JSON.stringify() method converts a JavaScript object or value to a JSON string; in this case, you simply need to determine whether the JSON string is "[]."
If so, there are no values in the array.
If not, there are values in the array.
let arr = [];let str=JSON.stringify(arr);if (str == '[]'){ console.log("No values in array");}else { console.log("array has values");}console.log(str);
About "es6 how to determine whether there is a value in the array" The content of this article is introduced here, thank you for reading! I believe everyone has a certain understanding of the knowledge of "how es6 judges whether there is a value in the array." If you still want to learn more knowledge, please pay attention to the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.