I need to separate all the characters of a string into an array, and I have a problem, my code is as follows
var PISCampos = campos.split("");
When I send in the variable fields the following string: "011001000000". Everything works, and I have tested with others like "000001000000" and the split works perfectly
But using this string: "100000000000" split does not work. I put an alert on the top line and one on the bottom line, only the first one works with this string, suggesting that the error is right there. The first alert displays the variable fields, and its value is correct.
TEST CODE
alert(campos);
var PISCampos = campos.split("");
alert("teste");
THE PROBLEM
I used this to retrieve the value I told them ("011001000000")
$("#campo option:selected" ).data("campos")
And my HTML was like this
<option data-campos="100000000000" value="53">Bla Bla Bla</option>
But from what I realized, since the first character was a nonzero number, jquery val () called it an integer, my fault, my sincere apologies.
SOLUTION
campos = campos.toString();
var PISCampos = campos.split("");