Javascript - 爆炸等效? [英] Javascript - explode equivilent?
本文介绍了Javascript - 爆炸等效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我有一个带分隔符的字符串| ,其中一个部分包含123,有没有办法找到这个部分并打印内容?
像PHP爆炸(但是Javascript),然后循环找到'123'可能? :/
So, I have a string with the delimiter | , one of the sections contains "123", is there a way to find this section and print the contents? something like PHP explode (but Javascript) and then a loop to find '123' maybe? :/
推荐答案
var string = "123|34|23|2342|234",
arr = string.split('|'),
i;
for(i in arr){
if(arr[i] == 123) alert(arr[i]);
}
或:
for(i in arr){
if(arr[i].indexOf('123') > -1) alert(arr[i]);
}
有关字符串$ c $的更多信息c>基于操作和函数参见:
For more information on string
based manipulation and functions see:
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String
这篇关于Javascript - 爆炸等效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文