R.H
R.H

Reputation: 318

How to split 2nd element in array in JavaScript?

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

Upvotes: 1

Views: 101

Answers (1)

Ahmed Lazhar
Ahmed Lazhar

Reputation: 866

Try this

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

Upvotes: 4

Related Questions