Separate 1 variable in 2 when you find a JS Script [duplicated]

-2

Cordial Greeting.

I tell you what I want to do.

Example, I have a variable like this:

var id = "673728-882";

What I want to do, is that I separate that into 2 variables where the script is, example of how it should be:

 var id2 = "673728";
  var id3 = "882";

I hope you understand me and can help me.

Thanks in advance

    
asked by Andres Rodriguez 22.11.2018 в 16:54
source

1 answer

1

try the split method of js. almost all languages have that method, you just have to pass as a parameter the variable you want to "delete"

    var id = "673728-882";
    var res = id.split("-");
// accedes con indices al vector que se creo con la variable res
    console.log(res[0]);
    console.log(res[1]);
    document.getElementById("demo").innerHTML = res[1];

I hope I helped you. Greetings!

    
answered by 22.11.2018 / 17:12
source