簡體   English   中英

用逗號分隔的Javascript字符串

[英]Javascript string separated by a comma

我試圖從字符串中獲取逗號之前/之后的所有內容

var test = 'hello,world';

結果:

   var one = 'hello';
   var two = 'world';

這會是一個好方法嗎?

謝謝

.split

額外的文字,因為我需要為此提交書寫15個字符才能獲得批准。

- 編輯

好吧,更明確地說:

var k = "a,b".split(",");
alert(k[0]);
alert(k[1]);
var test = 'hello,world',
    words = test.split(',');


   var one = words[0]; // hello
   var two = words[1]; // world

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM