Home >Web Front-end >JS Tutorial >JavaScript string replacement and string splitting sample code_javascript skills

JavaScript string replacement and string splitting sample code_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 17:09:281013browse

JS (JavaScript) string replacement function (a bit like PHP's preg_replace)

str.replace('xxx', 'yyyy'); Replace the first
str.replace(/xxx/g, 'yyyy'); Replace all

string splitting (similar to PHP's splitting function)

Copy code Code As follows:

var test = 'a-b-c-d';
test.split('-');
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