Issue
I have this array of array
a1 = [['one', 'two', ['three', 'four']], ['five', 'six', ['seven', 'eight']]];
how to get this 'three' and 'four', 'seven' and 'eight' out of child array and push it in parent array as string like below
a2 = [['one', 'two', 'three, four'], ['five', 'six', 'seven, eight']];
like this. can I solve it with ES6?
Note: with space between 'three' 'four' and 'seven' 'eight' as shown in a2.
Solution
Sounds like you want to join the inner arrays, yeah?
let a1 = [['one', 'two', ['three', 'four']], ['five', 'six', ['seven', 'eight']]];
let merged = a1.map((values) => {
return values.map((value) => {
return Array.isArray(value) ? value.join(', ') : value;
});
});
console.log(merged)
Answered By - nickf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.