I have a structure like [[[ ]]] which I want to convert to [].
[[[ ]]]
[]
E.g. [ [ [ \"Hi\" ] ] ] into [ \"Hi\" ]
[ [ [ \"Hi\" ] ] ]
[ \"Hi\" ]
How
This is exactly what flatMap() does:
let arr = [ [ [ "A", "B" ], ["C"] ], [ [ "D", "E" ], ["F"] ] ] // each call reduces the array by one dimension let flattened = arr.flatMap{$0}.flatMap{$0} // returns ["A", "B", "C", "D", "E", "F"]