user3171835
user3171835

Reputation: 13

How to convert a string into and array?

I have a string:

countries = "India,Bangladesh,Srilanka,South Africa,Australia,Canada"

I need to get an array from it:

countries = ["India","Bangladesh","Srilanka","South Africa","Australia","Canada"]

How I can do this?

Upvotes: 1

Views: 72

Answers (2)

backpackerhh
backpackerhh

Reputation: 2353

Try this:

countries = "India,Bangladesh,Srilanka,South Africa,Australia,Canada".split(',')

Upvotes: 2

Veeru
Veeru

Reputation: 356

By using the split method:

countries = countries.split(",")

Upvotes: 4

Related Questions