Languages
[Edit]
EN

JavaScript - replace part of string from given index

2 points
Created by:
Wesley
501

In this article, we're going to have a look at how to replace part of a string from a given index in JavaScript.

Quick solution:

Note: read this article to know how to remove part of text for given indexes.

Check the below example for a better solution.

 

Custom method example

Edit

Presented in this section solution allows inserting text outside of given string filling space with any characters (by default with space).

 

Custom method example (ES 2015)

Edit

ES 2015 introduced repeat() method for string.

 

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - String (popular problems)

JavaScript - replace part of string from given index
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join