Is it possible to use vanilla JavaScript in order to extract the first string value directly to the left of a specified portion of a longer string, excluding any blank spaces?
Consider the following string: 1 hr 30 min
How could you extract the 1
located to the left of hr
, and also how could you obtain the 30
situated to the left of min
?
let string = "1 hr 30 min";
if (string.includes("hr")) {
// code to retrieve the value 1
}
if (string.includes("min")) {
// code to retrieve the value 30
}