سؤال

I have an array like ["one, two, three"]. I want to convert it to ["one","two","three"]. I was using split to do this like:

$var temp=["one, two, three"];
temp.split(", ");

This is giving me error. Any idea how to do this?

هل كانت مفيدة؟

المحلول

It's an array with one single value, and you'd access that with [0] to get the string

var temp = ["one, two, three"];
var arr  = temp[0].split(", ");

seems easier to just drop the brackets

var arr = "one, two, three".split(', ');

or write it as an array to begin with ?

نصائح أخرى

["one, two, three"].pop().split(", ")
var temp=["one, two, three"];
temp[0].split(", ")
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top