Objective:
Extract the value "2TR" from "MARSSTANDGATA132TR" using JavaScript.
Need to determine the location of the digit 2 within the extracted string.
Issue:
Uncertain about the correct syntax to achieve this task.
Additional Details:
*The characters "TR" always appear at the end of the word.
*The digit "2" in "2TR" is individual and not part of a bigger number.
*Both the word and the address number vary.
*If the regex code fails to locate "TR" at the end of the word, the desired outcome cannot be retrieved.
function myFunction() {
var str = "MARSSTANDGATA132TR";
var n = str.search("TR");
document.getElementById("demo").innerHTML = n;
}
<button onclick="myFunction()">Test</button>
<p id="demo"></p>
Appreciate your help!