3428 posts Ruben Bristian
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 6-7 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 500 and 999 users
+5 more
KrownThemes says

Is there any function in js which removes the characters you sliced from the given string? For example:

var initVal = 'removeMEremoveME';
var tempVal = initVal.slice(initVal.lastIndexOf(['removeME']));

After running this, these are the things that i’m looking for:

initVal = 'removeME';
tempVal = 'removeME';

This is what i get instead:

initVal = 'removeMEremoveME';
tempVal = 'removeME';
304 posts
  • Austria
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 10 and 49 users
  • Sold between 10 000 and 50 000 dollars
squaredWeb says

The original initVal stays the same since you never actually change it. Why not just do:

var initVal = 'removeMEremoveME';
var tempVal = initVal.slice(initVal.lastIndexOf(['removeME']));
initVal=tempVal;
3428 posts Ruben Bristian
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 6-7 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 500 and 999 users
+5 more
KrownThemes says

Because in reality:

initVal = 'removeMEremoveMEremoveMEremoveMEremoveME';

And when i do your equality, my initVal is stripped down of all of the “removeME”s .. I need to remove them one by one..

304 posts
  • Austria
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 10 and 49 users
  • Sold between 10 000 and 50 000 dollars
squaredWeb says

I see, i didnt get that from the original post.

Well, you could do something like this: jsfiddle

Its not exactly elegant, but i think its ok to build upon.

5310 posts The Dude Abides
  • United States
  • Exclusive Author
  • Has been a member for 5-6 years
  • Elite Author
  • Bought between 100 and 499 items
  • Referred between 100 and 199 users
  • Author had a Free File of the Month
+5 more
CodingJack says
var initVal = 'removeMEremoveMEremoveMEremoveMEremoveME',
removeMes = initVal.split('removeME').join('|removeME').split('|'),
tempVal;

removeMes.shift();

while(removeMes.length) {

    removeMes.shift();

    tempVal = removeMes.toString().split(',').join('');

    console.log(tempVal);

}

Traces:

removeMEremoveMEremoveMEremoveME
removeMEremoveMEremoveME
removeMEremoveME
removeME
by
by
by
by
by
by