3696 posts Ruben Bristian
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
+10 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';
325 posts
  • Sells items exclusively on Envato Market
  • Has been a beta tester for an Envato feature
  • Has sold $10,000+ on Envato Market
  • Has referred 10+ members
+2 more
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;
3696 posts Ruben Bristian
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
+10 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..

325 posts
  • Sells items exclusively on Envato Market
  • Has been a beta tester for an Envato feature
  • Has sold $10,000+ on Envato Market
  • Has referred 10+ members
+2 more
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.

5406 posts The Dude Abides
  • Located in United States
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
+9 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

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by