//类型转换
//Object 与 MAP 转换
let obj = {
name:'xiaoming',
age:19
}
let map = new Map(Object.entries(obj)) //接收键值对
let obj2 = Object.fromEntries(map)
console.log('map',map,'obj',obj2);
//Array 与 Set 转换
let arr = [1,1,2,2,3,3,4]
let set= new Set(arr)
let arr2 = Array.from(set)
console.log('arr',arr2,'set',set);
输出结果:
map Map(2) {'name' => 'xiaoming', 'age' => 19} obj {name: 'xiaoming', age: 19}
arr (4) [1, 2, 3, 4] set Set(4) {1, 2, 3, 4}