admin管理员组文章数量:1026653
This is probably very elementary, but I'm still learning.
I've imported a record from an XML file and have the result :
"a,b,c,d,e,f,g,h"
I would like to end up with 8 separate variables, one for each ma delimited value.
What is the shortest way to code this using javascript?
This is probably very elementary, but I'm still learning.
I've imported a record from an XML file and have the result :
"a,b,c,d,e,f,g,h"
I would like to end up with 8 separate variables, one for each ma delimited value.
What is the shortest way to code this using javascript?
- 1 do you mean split? ~ Further learning: developer.mozilla/en/JavaScript/Reference/Global_Objects/… – jcolebrand Commented Dec 2, 2010 at 17:15
- Yes, SPLIT, now a term I will never forget. I'm still learning the proper terminology. The theory is always so clear in my head...I just jumble syntax in the transcription, ha! – Kirt Commented Dec 2, 2010 at 18:48
4 Answers
Reset to default 4if you .split() the list, you'll end up with a single array with 'n' number of elements. Not -exactly- 8 separate variables, but 8 elements that can be accessed individually.
var myList = "a,b,c,d,e,f,g,h";
var myArray = myList.split( ',' );
alert( myArray[ 4 ] );
use split()
js>s = "a,b,c,d,e,f,g,h"
a,b,c,d,e,f,g,h
js>a = s.split(',')
a,b,c,d,e,f,g,h
js>a[0]
a
js>a[4]
e
Use split().
In your case, xml_string.split(',');
If you have the result as a string, use the split
method on it:
var myList = "a,b,c,d,e,f,g,h";
var myArray = myList.split(",");
This is probably very elementary, but I'm still learning.
I've imported a record from an XML file and have the result :
"a,b,c,d,e,f,g,h"
I would like to end up with 8 separate variables, one for each ma delimited value.
What is the shortest way to code this using javascript?
This is probably very elementary, but I'm still learning.
I've imported a record from an XML file and have the result :
"a,b,c,d,e,f,g,h"
I would like to end up with 8 separate variables, one for each ma delimited value.
What is the shortest way to code this using javascript?
- 1 do you mean split? ~ Further learning: developer.mozilla/en/JavaScript/Reference/Global_Objects/… – jcolebrand Commented Dec 2, 2010 at 17:15
- Yes, SPLIT, now a term I will never forget. I'm still learning the proper terminology. The theory is always so clear in my head...I just jumble syntax in the transcription, ha! – Kirt Commented Dec 2, 2010 at 18:48
4 Answers
Reset to default 4if you .split() the list, you'll end up with a single array with 'n' number of elements. Not -exactly- 8 separate variables, but 8 elements that can be accessed individually.
var myList = "a,b,c,d,e,f,g,h";
var myArray = myList.split( ',' );
alert( myArray[ 4 ] );
use split()
js>s = "a,b,c,d,e,f,g,h"
a,b,c,d,e,f,g,h
js>a = s.split(',')
a,b,c,d,e,f,g,h
js>a[0]
a
js>a[4]
e
Use split().
In your case, xml_string.split(',');
If you have the result as a string, use the split
method on it:
var myList = "a,b,c,d,e,f,g,h";
var myArray = myList.split(",");
本文标签: javascriptHow do I separate a comma delimited variable into multiple variablesStack Overflow
版权声明:本文标题:javascript - How do I separate a comma delimited variable into multiple variables? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745651292a2161333.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论