1. 定义set
let manage_ip = new Set();
manage_ip.add(1)
manage_ip.add(1)
manage_ip.add(2)
manage_ip.add(2)
manage_ip.add(3)
manage_ip.add(4)
console.log(manage_ip.size);
let manage_ip = new Set([1,2,3,4,4,]);
2. set 与 数组 相互转换
2.1 array --> set (数组转set)
let array = [1, 2, 3, 4];
let set = new Set(array);
2.2 set --> array (使用Array.from()方法)
let demo = new Set([1,2,3,4]);
Array.from(demo)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)