Taiwo Sulaimon
Taiwo Sulaimon

Reputation: 53

Getting out a string and inserting it into an array separately

I have an array like this

["Billboard,Television"]

and I want something like this

["Billboard", "Television"]

Upvotes: 0

Views: 23

Answers (2)

Ketan Ramteke
Ketan Ramteke

Reputation: 10655

few other ways:

let str2 = ["Billboard,Television", "have,an,array,like,this"]
let sol = str2.toString().split(",")
console.log(sol)

let str2 = ["Billboard,Television", "have,an,array,like,this"]
let sol = str2.join(",").split(",")
console.log(sol)

Upvotes: 1

Ramesh Reddy
Ramesh Reddy

Reputation: 10662

You can use flatMap and split for that:

const bla = ["Billboard,Television"];

const result = bla.flatMap(el => el.split(','));
console.log(result)

Upvotes: 1

Related Questions