How to convert Set to Array?

前端 未结 10 1087
余生分开走
余生分开走 2020-11-28 01:04

Set seems like a nice way to create Arrays with guaranteed unique elements, but it does not expose any good way to get properties, except for generator [Set

10条回答
  •  借酒劲吻你
    2020-11-28 01:36

    The code below creates a set from an array and then, using the ... operator.

    var arr=[1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,];
    var set=new Set(arr);
    let setarr=[...set];
    console.log(setarr);
    

提交回复
热议问题