JavaScript
Article
By Sam Deering

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:

--ADVERTISEMENT--

console.log($itemForm.substring(lastRowIndex, $itemForm.length));
$itemForm = $itemForm.substring(0,lastRowIndex) + "" + data.tableRowTemplate.html() + "" + $itemForm.substring(lastRowIndex, $itemForm.length);
console.log($itemForm);
Recommended
Sponsors
The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
Login or Create Account to Comment
Login Create Account