ES6 basic syntax (III) -- data set

H⃰U⃰A⃰ 2021-09-15 09:16:57
3、 ... and 、 Data set -set
· It's like an array , The difference is set There's no duplicate data in it
· It is mainly used to remove duplicate data
1. Create a collection
let set = new Set([' Zhang San ', ' Li Si ', ' Wang Wu ', ' Zhang San ', ' Li Si ']);
console.log(set);
Set(3)
size:(...)
__proto__:Set
[[Entries]]:Array(3)
0:" Zhang San "
1:" Li Si "
2:" Wang Wu "
length:3
2. An attribute
console.log(set.size); // 3
3. Four ways
// add
console.log(set.add(' Lau Andy ').add(' Xuan Zhihua '));
// delete
console.log(set.delete(' Zhang San '));
// has
console.log(set.has(' Zhang San ')); // true
// clear Empty
console.log(set.clear()); // undefined
console.log(set);
// keys values equally
console.log(set.keys());
console.log(set.values());
//SetIterator {" Zhang San ", " Li Si ", " Wang Wu "}

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
Please bring the original link to reprint ,thank
Similar articles

2021-09-15

2021-09-15