Bottom is a simple solution to an algorithm to which I will be referring. My question comes in a return I received when I altered the return to be result
instead of result[0]
The console returned
['123, index: 0, input: ‘123aa1’, groups: undefined]
What is going on here? What kind of phenomenon have invoked by not including the index number [0]
with result
? I haven’t encountered this before.
function longestDigitsPrefix(inputString: string): string {
const result = inputString.match(/^\d*/);
if (result !== null) {
return result[0];
return "";
}
}
console.log(longestDigitsPrefix("123aa1"));