# Implement the String.prototype.remove

**URL:** <https://es.discourse.group/t/implement-the-string-prototype-remove/2526>\
**Category:** 🦋 Proposals\
**Tags:** proposal\
**Created:** [March 22, 2026, 6:46pm UTC](https://es.discourse.group/t/implement-the-string-prototype-remove/2526 "2026-03-22T18:46:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hotequil](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/hotequil/32/2507_2.png) [@hotequil](https://es.discourse.group/u/hotequil)\
**Post date:** [March 22, 2026, 6:46pm UTC](https://es.discourse.group/t/implement-the-string-prototype-remove/2526/1 "2026-03-22T18:46:18Z")

</div>

# Hi guys!

The motivation behind this proposal is to simplify the text replacement within JavaScript. Currently, to remove some text in a `string`, you need to use the `replace` or `replaceAll` methods passing an empty `string` as a second parameter. This is an ugly way. So this proposal doesn't change the memory value and removes the second parameter.

## How it works

It receives one **string** or **RegExp** that returns a new **string**.

## Cases

```typescript
// Imports omitted…

"bitcoin-mainnet".remove("-mainnet")
// "bitcoin"

"bitcoin-mainnet".remove(/-mainnet/)
// "bitcoin"

"bitcoin mainnet mainnet".remove("mainnet", { trim: true })
// "bitcoin"

"bitcoin mainnet mainnet".remove(/mainnet/, { trim: true })
// "bitcoin"

```

## Install the polyfill

```bash
// Use your favorite package manager

npm install @hotequil/proposal-remove-string

```

## Import the polyfill

```typescript
// Import it in your main, index or app file

import "@hotequil/proposal-remove-string"

```

---

<div class="post-metadata">

**Author:** ![michael](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/michael/32/11_2.png) [@michael](https://es.discourse.group/u/michael)\
**Post date:** [April 10, 2026, 5:35pm UTC](https://es.discourse.group/t/implement-the-string-prototype-remove/2526/2 "2026-04-10T17:35:55Z")

</div>

Your proposal is motivated by not having to type `, ""` in a call to `replaceAll`? And you also want a feature where you can use `, { trim: true }` instead of `.trim()`?

---

<div class="post-metadata">

**Author:** ![hotequil](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/hotequil/32/2507_2.png) [@hotequil](https://es.discourse.group/u/hotequil)\
**Post date:** [April 19, 2026, 10:46pm UTC](https://es.discourse.group/t/implement-the-string-prototype-remove/2526/3 "2026-04-19T22:46:19Z")

</div>

Hi, @michael!

It's not a good idea to have the `.trim()`. I removed it.

About the other question, a native `.remove()` method is more semantic and declarative than using `.replace()` or `.replaceAll()`. It explicitly communicates the intent to delete a string, reducing boilerplate and making the code more readable by avoiding 'magic' empty strings.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [April 20, 2026, 4:33am UTC](https://es.discourse.group/t/implement-the-string-prototype-remove/2526/4 "2026-04-20T04:33:15Z")

</div>

It's not magic, though - it's literally saying "replace X with nothing". I agree there's a very tiny readability benefit to having "remove", but I'm not sure it's worth it to add something to the language just for that.

---

<div class="post-metadata">

**Author:** ![hotequil](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/hotequil/32/2507_2.png) [@hotequil](https://es.discourse.group/u/hotequil)\
**Post date:** [April 21, 2026, 2:22am UTC](https://es.discourse.group/t/implement-the-string-prototype-remove/2526/5 "2026-04-21T02:22:19Z")

</div>

Yes, that makes sense.
