2016-10-01 58 views
-1

如何将像["text1 text2"]这样的对象拆分为仅在javascript中显示text1 text2字符串?如何使用split()函数在javascript中分割字符串

+3

'[“text1 text2”]'是一个数组,而不是一个字符串。它没有'split()'方法 – Tibrogargan

+0

简单地使用你的arrayname [0]。它会返回text1 text2 –

+0

[Split JavaScript string with conditions]的可能重复(http://stackoverflow.com/questions/33127397/split-javascript-string-with-conditions) –

回答

0

由于Tibrogargan在上面的评论中表示,["text1 text2"]是一个数组。该数组包含一个字符串值"text1 text2",可以通过在数组中使用索引(获取该特定项目)或循环访问数组中的所有项目(如果需要所有项目)来访问该数组。

对于你的情况,它很容易使用索引。

var stringArray = ["text1 text2"]; 
console.log(stringArray[0]); 
// text1 text2 should be logged into console 

查看here了解更多文档。

2

你只想访问里面的值? ["text1 text2"][0]会返回字符串,text1 text2

相关问题