Convert nested array in swift to single dimensional array

后端 未结 4 1708
谎友^
谎友^ 2021-01-29 12:59

I have a structure like [[[ ]]] which I want to convert to [].

E.g. [ [ [ \"Hi\" ] ] ] into [ \"Hi\" ]

How

4条回答
  •  时光说笑
    2021-01-29 13:23

    you can use join as

    let numbers = [[1,2,3],[4],[5,6,7,8,9]]
    let newArray = Array(numbers.joined().joined())
    print(newArray)//[1,2,3,4,5,6,7,8,9]]
    

提交回复
热议问题