I have an input which is always a String. The string can contain an integer or text:
intputString = "1";
or
inputString = "hey";
I would like to convert to a Number only those inputs that contain integers. Otherwise, the inputs need to remain the same.
For example, if I have an integer:
inputString = "288"; // <-- Make the conversion
desiredOutput = 288;
And if I have non-integer text:
inputString = "hey"; // <-- Don't make the conversion and leave it as is
desiredOutput = "hey";
I was using Numbers(inputString)
but this converts text values into NaN
.
How can I achieve this conversion?
EDIT: None of the answers from the duplicate question answers this question.