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 an array contains the same value in javascript

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

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the javascript es6 how to judge whether the array contains the same value, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Judgment method: 1, the array into the Set collection, and use the size attribute to get the total number of Set elements, syntax "new Set (arr) .size"; 2, use the length attribute to obtain the total number of array elements; 3, compare the total number of Set elements and the total number of array elements are equal, not equal, it contains the same value, otherwise there is no.

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

In es6, you can use Set to determine whether there are the same elements in the array.

ES6 provides a new data structure in which the values of members in Set,Set are unique and there are no duplicate elements.

The method of determining whether there are the same elements in an array:

Converts the array to Set and uses the size attribute to return the total number of current Set elements

Determine whether the total number of Set elements is equal to the total number of array elements

Let arr = [1console.log (arr). Size! = = arr.length) {console.log ("have the same element-Yes");} else {console.log ("no same element-No");}

Thank you for reading this article carefully. I hope the article "how to determine whether an array of es6 in javascript contains the same value" shared by the editor is helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you 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