Javascript - explode equivilent?

const string = "123|34|23|2342|234";
const arr = string.split('|');

for(let i in arr){
    if(arr[i] == 123) alert(arr[i]);
}

Or:

for(let i in arr){
    if(arr[i].indexOf('123') > -1) alert(arr[i]);
}

Or:

arr.forEach((el, i, arr) => if(arr[i].indexOf('123') > -1) alert(arr[i]) }

Or:

arr.forEach((el, i, arr) => if(el == '123') alert(arr[i]) }

Or:

const arr = "123|34|23|2342|234".split('|')

if(arr.some(el=>el == "123")) alert('123')

More information on string and Array memeber functions.


You can use split() in JavaScript:

var txt = "123|1203|3123|1223|1523|1243|123",
    list = txt.split("|");

console.log(list);

for(var i=0; i<list.length; i++){
    (list[i]==123) && (console.log("Found: "+i));  //This gets its place
}

LIVE DEMO: http://jsfiddle.net/DerekL/LQRRB/