How to use replace, split and slice methods of strings in Javascript?

In the web applications we develop, processing strings is the most commonly used function, this post will introduce : ① How to replace Javascript strings? ② How to split a string to generate an array? ③ How to slice a string by index?

Keywords: Javascript , strings , replace , split , slice.

Replace

In Javascript, replacing the content of a string requires the use of the replace() function. Here are a few common examples.

Split

In Javascript, splitting a string needs to use the split() function, and specify what character to split according to, the function returns an array.

Slice

In Javascript, you need to use slice(start, end) function to intercept a string, where start represents the start-offset and end represents the end-offset.

In Javascript, we can use replace(), split(), slice() functions to replace, split, and intercept strings respectively. The result type returned by split() is array. For other operations of array type, please read related articles.

Edit Template

Leave a Reply

Your email address will not be published. Required fields are marked *

Chaoxu Wei

Master student at Tongji University (Writer & Blogger)

Job hunting, both part-time and full-time jobs are accepted. Job recommendation please email me weichaoxu1998@gmail.com, thank you very much!

0
0
Edit Template

“There are many people in the world who want to work hard but can’t, and people who work too hard and are exhausted. Please don’t use your efforts only to chase your own victory, please use them to help others.”

Follow

Contact

libertynlp@163.com

+86-18385537403

Yangpu District, Shanghai