I have a string like this (HTML select list):
const config = {
"celsius": {
"celsius": v => v,
"fahrenheit": v => v * 1.8 32,
"kelvin": v => v 273.15,
"rankine": v => (v 273.15) * 1.8,
"reaumur": v => v * 0.8,
},
// more...
}
And I want to cut the first 5 characters from the output (operationPlace)
var listOperation = config[listFromV][listToV].substring(5);
document.getElementById("operationPlace").innerHTML = listOperation;
// now it looks like this: v => v or v => v * 1.8 32 etc.
// should look like this: v or v * 1.8 32 etc. (I'd like to change that "v" to numbers from the input (inputPlace) too)
I tried using substring, but it didn't work. Is there a way to do this?
CodePudding user response:
You can obtain the definition of a function in the form of a string by calling .toString
on it, then call .substring
to get rid of the function signature part:
var listOperation = config[listFromV][listToV];
document.getElementById("operationPlace").innerHTML = listOperation.toString().substring(5);
CodePudding user response:
Convert this string to an array and then pull out your desired values.