Search code examples
javascriptjqueryangularjsparseint

parseInt of ranged(31-40) string in Javascript


I'm not able to convert integer of ranged string. I have a age group of 21-30, 31-40,41-50 etc, I have to convert selected string and send to server. I have tried with parseInt method but not working. Below is the code,

var ageSelected = '31-40';
parseInt(ageSelected) //Output is only first number 31 NOT 31-40

Please anybody have idea about this, please help me


Solution

  • System don't understand what is 31-40. It can't be a valid integer. You can either send it as a String to the server and process there or send as two separate integers.

    var ageSelected = '31-40';
    parseInt(ageSelected.split("-")[0]) //start age
    parseInt(ageSelected.split("-")[1]) // end age