im trying to remove brackets and 2 letters from an API response that i got with axios, i show the data with vue js but they are showing like this :
["188 cm"]
What will be the best way to only show 188 by removing Brackets and cm [" cm"] ?
Thank you
"Removing the brackets" is the straightforward part. What you have is simply an array with one element, so you can access the first element in that array. (Assuming of course there's always at least one element, if it's possible for the array to be empty then you will want to put in some range checking before trying to access the element.)
The second part, "removing the ' cm' part", can be done in a couple of different ways. You can split the string on the space character and take the first part of the result, you can simply replace " cm" with "", or if what you want is the actual number and the string always starts with that number then parseInt will ignore everything after that number by default.
For example:
let theArray = ["188 cm"];
let theString = theArray[0];
let theNumber = parseInt(theString);
console.log(theNumber);