Home > Back-end >  How to split 2nd element in array in JavaScript?
How to split 2nd element in array in JavaScript?

Time:08-04

How to split 2nd value in array?

Input [["ABCD","123,456"],["EFGH","565,565,878"]]

Required Output [["ABCD","123","456"],["EFGH","565","565","878"]]

I tried array.map(x => x[1].split(',')) but I am getting output as [["123","456"]],["565","565","878"]] 1st value is getting omitted. How to include 1st value also? If I use x.split(',') I am getting error

x.split is not a function

CodePudding user response:

Try this

input.map(([name, list])=>[name, ...list.split(',')])
  • Related