Home >Web Front-end >Front-end Q&A >How to delete substring in es6

How to delete substring in es6

青灯夜游
青灯夜游Original
2022-05-07 18:16:162020browse

Two methods to delete substrings: 1. Use replace() to remove the first substring that appears in the string. The syntax is "string object.replace("substring value","")" ;2. Use replaceAll() to remove all substrings, the syntax is "string object.replaceAll("substring value","")".

How to delete substring in es6

The operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.

How to delete substrings in a string in es6

1. Use the replace() function

replace() method is used to replace some characters in a string with a substring of other characters.

The specified substring can be deleted when the replacement value is a null character.

var str = "Hello world!";
var n=str.replace("Hello","");
console.log(n);

How to delete substring in es6

replace() function only replaces the first matching substring:

var str="Visit Microsoft! Visit Microsoft!";
var n=str.replace("Microsoft","");
console.log(n);

How to delete substring in es6

2 , use the replaceAll() function

replaceAll() method is used to replace some characters with other characters in a string, or replace a substring that matches a regular expression. This function will replace all The matched substring.

Similarly, when the replacement value is a null character, the specified substring can be deleted.

var str = "Hello world!";
var n=str.replaceAll("world","");
console.log(n);

How to delete substring in es6

The replaceAll() function will replace all matching substrings:

var str="Visit Microsoft! Visit Microsoft!";
var n=str.replaceAll("Microsoft","");
console.log(n);

How to delete substring in es6

[Related recommendations: javascript video tutorialwebfrontend

The above is the detailed content of How to delete substring in es6. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn