Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

js set转array

作者:木の兮   发布日期:2025-10-03   浏览:88

// 将 Set 转换为 Array 的示例代码

// 创建一个新的 Set 对象
const mySet = new Set([1, 2, 3, 4, 5]);

// 使用 Array.from() 方法将 Set 转换为数组
const arrayFromSet = Array.from(mySet);

// 或者使用扩展运算符(...)将 Set 转换为数组
const arrayFromSetSpread = [...mySet];

console.log(arrayFromSet);        // 输出: [1, 2, 3, 4, 5]
console.log(arrayFromSetSpread);  // 输出: [1, 2, 3, 4, 5]

// 解释:
// 1. Array.from() 方法可以将任何可迭代对象(如 Set)转换为数组。
// 2. 扩展运算符(...)也可以用于将 Set 展开成一个数组字面量。

上一篇:js setdate()

下一篇:js set方法

大家都在看

js 数组对象排序

js 数组删掉第一个值

js fill

js 数组连接

js json数组

js 数组复制

js 复制数组

js 数组拷贝

js 对象数组合并

js 对象转数组

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站