JavaScript
Article

jQuery find index of last string

By Sam Deering

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);

No Reader comments

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.