<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>set 类型转换</title> </head> <body> <script> // Array 转 Set var mySet = new Set(["1", 2, "3"]); console.log("mySet:", mySet); // mySet: Set(3) {"1", 2, "3"} // 用“...”操作符,将 Set 转 Array var myArray = [...mySet]; console.log("myArray:", myArray); // myArray: (3) ["1", 2, "3"] // String 转 Set var mySet = new Set('hello'); console.log("mySet:", mySet); // mySet: Set(4) {"h", "e", "l", "o"} </script> </body> </html>
js set 类型转换
最新推荐文章于 2024-06-04 14:30:00 发布