How to avoid Object is possibly null in VSCode though code runs ok
let url = 'https://test.com/test/varstring/stringtoextract?id=test3' let regex = /https://test.com/test/varstring/.+/(.+)?.+/ var match = regex.exec(url); alert(match[1]);
If you are sure, use the Non-null assertion operator !:
!
alert(match![1]);
Of course, an if statement would also do the trick:
if
if (match) { alert(match[1]); }
2.1m questions
2.1m answers
60 comments
57.0k users