jQuery find index of last string

Sam Deering
Share

Quick jQuery snippet to insert into string at a specific index (or a last string). For example, to find the last position of a table row.

//find last position of 
 var lastRowIndex = $itemForm.lastIndexOf('');
 console.log(lastRowIndex);

You could then insert the string into the index of another string like so:

console.log($itemForm.substring(lastRowIndex, $itemForm.length));
$itemForm = $itemForm.substring(0,lastRowIndex) + "" + data.tableRowTemplate.html() + "" + $itemForm.substring(lastRowIndex, $itemForm.length);
console.log($itemForm);