function(obj){
if(obj == undefined || obj == null){
return '';
}
var id = obj.match(/\d+$/);
return id || '';
}
I have a DOM element that looks like:
id="some-text-123"
and I want the ‘123’ part of the id to be returned when calling the above function.
other elements might be like:
id="123"
id="some-123"
id="some-ting-else-1"
I called this on an element that looked like “some-text-213”
and it seemed to return an array, I just want the id returned.
The
matchmethod returns an array, the first item of which contains the entire matched text. Update yourreturnstatement to reflect this: