I have a multidimensional array:
var array 1 =
[
[[Name 1, 2, Nigeria],
[Name 3, 52, Egypt],
[Name 5, 75, South Africa]]
[[Name 5, 8, Nigeria],
[Name 1, 62, Egypt],
[Name 3, 115, South Africa]]
[[Name 6, 88, Nigeria],
[Name 3, 92, Egypt],
[Name 5, 825, South Africa]]
]
I want to have a new flat array:
var array 2 = [Name 1, Name 3, Name 5, Name 5, Name 1, Name 3, Name 6, Name 3, Name 5]
I've tried writing a function that maps over the array and returns the first element:
function name(filteredName){
filteredName.map(function(firstName){
return firstName[0]
})
}
However, this just returns:
[Name 1, Name 1, Name 1]
I'm really not sure how to solve this! Any help would be great.
name()? If you calledname(array1), It won't return anything. Your array isn't a array either. It's syntactically inaccurate. Your example is neither complete nor verifiable.