I have this string:
0000000020C90037:TEMP:data
I need this string:
TEMP:data.
With PHP I would do this:
JavaScript
x
4
1
$str = '0000000020C90037:TEMP:data';
2
$arr = explode(':', $str);
3
$var = $arr[1].':'.$arr[2];
4
How do I effectively explode
a string in JavaScript the way it works in PHP?
Advertisement
Answer
This is a direct conversion from your PHP code:
JavaScript
1
14
14
1
//Loading the variable
2
var mystr = '0000000020C90037:TEMP:data';
3
4
//Splitting it with : as the separator
5
var myarr = mystr.split(":");
6
7
//Then read the values from the array where 0 is the first
8
//Since we skipped the first element in the array, we start at 1
9
var myvar = myarr[1] + ":" + myarr[2];
10
11
// Show the resulting value
12
console.log(myvar);
13
// 'TEMP:data'
14