-4

I need to read the numeric value of one line in a text file

color=7

so var color will = 7

LuaStart
  • 397
  • 2
  • 11

1 Answers1

-1

Split the string by '=', get the second value and turn it into an int:

let data = 'color=7';
let color = parseInt(data.split('=')[1]);
console.log(color);

Do note that if the value after the = isn't a number in this case, the code will throw an excpetion so you might wanna catch it.

DaCurse
  • 795
  • 8
  • 25