Issue
I have this array of array
a1 = ['one', 'two', ['three', 'four']];
how to get this 'three' and 'four' out of child array and push it in parent array as string like below
a2 = ['one', 'two', 'three, four'];
like this. can I solve it with ES6?
Note: with space between 'three' and 'four' as shown in a2.
Solution
You can use map() and conditionally join() the subarray's values:
const a1 = ['one', 'two', ['three', 'four']];
const a2 = a1.map(v => Array.isArray(v) ? v.join(', ') : v);
console.log(a2);
Answered By - Robby Cornelissen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.