简体   繁体   中英

How to split a string in javascript using the split() function

如何拆分["text1 text2"]类的对象,以便仅在javascript中显示text1 text2字符串?

You just want to access the value inside? ["text1 text2"][0] would return the string, text1 text2

As Tibrogargan said in the comments above, ["text1 text2"] is an array. This array contains one string value "text1 text2" which can be accessed either by using it's index inside an array (to get that specific item) or by looping through all the items inside the array (if you want all items).

For your case, it's easy to use index.

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

Check here for more documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM