Home  >  Article  >  Web Front-end  >  javascript: concatenating string function concat()

javascript: concatenating string function concat()

高洛峰
高洛峰Original
2016-11-16 10:39:142916browse

String.prototype.concat()

concat() method connects and merges one or more strings with the original string to form a new string and return it, without affecting the original string.

Syntax

str.concat(string2, string3[, ..., stringN])

Parameters

string2...stringN

Multiple strings connected to the original string

Description

concat method combines one or more strings with the original string to form a new string and returns it. The concat method does not affect the original string.

Example

The following example demonstrates how to merge multiple strings with the original string into a new string.

var hello = "Hello, ";
console.log(hello.concat("Kevin", " have a nice day.")); /* Hello, Kevin have a nice day. */

Performance

It is strongly recommended to use assignment operators (+, +=) instead of concat method.

Browser compatibility

Full platform support.


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