I'm trying to get a value that's between, next or before of a comma.
For example, my string is: "value1,value2,value3,value4"
, sent to JS through PHP (ajax)
How do I just get value2
and value4
inside the .js file?
I'm trying to get a value that's between, next or before of a comma.
For example, my string is: "value1,value2,value3,value4"
, sent to JS through PHP (ajax)
How do I just get value2
and value4
inside the .js file?
let myString = "value1,value2,value3,value4"
myString.split(',')
console.log(myString.split(','))
let szResult = "val1,val2,val3,val4";
let arr = szResult.split(',');
console.log(arr[1]); // val2
console.log(arr[3]); // val4
Use split() function like that:
var arr = yourString.split(",")
// value2
return arr[1]
// value 3
return arr[3]
It's pretty simple, I don't think it is really issue for the question here, sorry.