# Set Set 对象是值的集合,你可以按照插入的顺序迭代它的元素。Set 中的元素只会出现一次,即 Set 中的元素是唯一的。 ## 实例属性 ### size ```ts const set1 = new Set(); set1.add(42); set1.add('forty two'); set1.add('forty two'); console.log(set1.size); // expected output: 2 ``` ## 实例方法 ### add(value) ```ts const set1 = new Set(); set1.add(42); set1.add(42); set1.add(13); set1.forEach((item)=>{ console.log(item); // expected output: 42 // expected output: 13 }) ``` ### clear() ```ts const set1 = new Set(); set1.add(1); set1.add('foo'); console.log(set1.size); // expected output: 2 set1.clear(); console.log(set1.size); // expected output: 0 ``` ### delete(value) ```ts const map1 = new Map(); map1.set('bar', 'foo'); console.log(map1.delete('bar')); // expected result: true // (true indicates successful removal) console.log(map1.has('bar')); // expected result: false ``` ### forEach(callbackfn, thisArg?) ```ts const set1 = new Set([42, 13]); set1.forEach((item)=>{ console.log(item); // expected output: 42 // expected output: 13 }) ``` ### has(value) ```ts const set1 = new Set([1, 2, 3, 4, 5]); console.log(set1.has(1)); // expected output: true console.log(set1.has(5)); // expected output: true console.log(set1.has(6)); // expected output: false ``` . ## Bug & Tips@tips * 目前 Set 类型编译到 kotlin 为 io.dcloud.uts.UTSSet