If I get two values separated by "-" like:
"first value-second value"
What's a good way to find both in JS?
Thanks!
If I get two values separated by "-" like:
"first value-second value"
What's a good way to find both in JS?
Thanks!
var str = "first value-second value",
arr = str.split('-');
console.log(arr[0]); //'first value'
console.log(arr[1]); //'second value'
The split() method is used to split a string into an array of substrings, and returns the new array.
var str = "first value-second value",
var value = str.split("-");
alert(value[0]);// print first value
alert(value[1]);// print second value