Title: convertion/Flattening of Some(Array(Array(Array(String)))) to Array(String)
Tags: scala;user-defined-functions;scala-collections
Question: I have an ```Option[Array[Array[Array[String]]]]``` and I want to convert to it ```Array[String]``` or Atleast ```Some(Array[String])```.

I have tried with ```.flatten``` method.

I can print using ```.map(_.map(_.map(_.foreach(print))))``` but want to store this printed thing as List.

Expectation: ```Array[String]``` or ```Some(Array(String))```.

Comment: In order to provide a [mcve] it's better to also add an example of a data set you are trying to convert.

Comment: Please format your code when asking your question.


Here is another answer: If you know exactly the Structure you can do:

For ```Option[Array[String]]```

```myArray.map(_.flatten.flatten)
```

For ```Array[String]```:

```myArray.toArray.flatten.flatten.flatten
```

Comment for this answer: I added also a version for `Array[String]`

Here is another answer: To convert ```Option[Array[Array[Array[String]]]]``` to ```Option[Array[String]]``` do this:

```.map(_.flatten.flatten)
```

To print the data inside the result, do this

```.foreach(_.foreach(println))
```


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:07/15/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<scala><user-defined-functions><scala-collections>', 'Title': 'convertion/Flattening of Some(Array(Array(Array(String)))) to Array(String)', 'ViewCount': 69, 'id': 57035886, 'user_AboutMe': '<p>I am a data engineer. Currently working as a big data engineer. Exploring machine learning and AI. My weapons: Python, Scala, Pyspark, SQL, Spark, Databricks, AWS EMR, AWS Redshift, AWS S3, AWS</p>\n', 'user_AccountId': 16059136.0, 'user_DisplayName': 'Learnis', 'user_Reputation': 446.0, 'user_Views': 146.0, 'user_id': 11590582.0}}