I have the following code:
if ($selectInput.data('propagate-title') === 'yes') {
var m = this.id.match(/^modal_TempRowKey_(\d+)$/);
if (m) {
$("#modal_Title_" + m[1]).val(title);
}
}
Can someone explain what is returned and put into m. Can I just change the code to the following and have it work the same?
if ($selectInput.data('propagate-title') === 'yes') {
var m = this.id.match(/^modal_TempRowKey_(\d+)$/)[1];
if (m) {
$("#modal_Title_" + m).val(title);
}
}
There is an important difference between the two code fragments. You can not make the change you wish because if there is no match,
nullwill be returned from thematchoperation, and the result of evaluatingwould throw an error, something like
The return value of
matchis an array if the regex matches, ornullif there is no match. Element 0 of the returned array is the whole match, element 1 would be the match within the parenthesis-pair starting with the first(. In the first code fragment, the valuem[1]is the digit sequence following"modal_TempRowKey_".EDIT: See the link provided by Kyle in the comment to the original question for all the details.