How to connect strings in js
JS method of connecting strings: 1. Use the string concatenation operator " " to connect strings; 2. Use the concat() method of strings to connect strings; 3. Use the join() method of arrays connection string.
The operating environment of this article: Windows 7 system, Dell G3 computer, javascript version 1.8.5.
JS methods for connecting strings include: using the string concatenation operator " ", using the concat() method, and using the join() method.
In JavaScript, we can connect two or more strings to form a new string. This article will introduce you to the method of connecting strings in js, so that you can have some knowledge about string connections. I have a certain understanding, I hope it will be helpful to you.
String concatenation operator " "
" " " operator can be used to add strings to connect two or more string variables.
Example:
<div class="demo "> <p>str1="What a very"</p> <p>str2="nice day"</p> <p id="str3"></p> </div> <script type="text/javascript"> var str1="What a very"; var str2="nice day"; var str3= str1+" "+str2; document.getElementById("str3").innerHTML ="str3='"+str3+"'"; </script>
Rendering:
In the above example, the strings str1 and str2 are changed through the " " operator There is also an empty string concatenated to form a new string str3.
Concat() method of string
The concat() method is used to concatenate two or more strings or arrays and then return A new string or array.
Syntax:
string1. concat([string2[, string3[, . . . [, stringN]]]])
string1: Specify a String object or string carrier, and all other specified strings can be connected to this carrier; required.
string2,. . ., stringN: The optional parameter (one or more) in the concat() method is a string appended to the end of the string1 carrier.
Note:
1. If the specified string1 carrier is different and the parameters in the concat() method are different, the new string formed will also be different.
2. If there are parameters that are not strings in the concat() method, they will be converted into strings first and then connected to the end of string1.
Example: concat() method to connect string
<div class="demo "> <p>str1="12q"</p> <p>str2="12w"</p> <p>str3="111"</p> <p id="str4"></p> <p id="str5"></p> <p id="str6"></p> </div> <script type="text/javascript"> var str1='12q'; var str2="12w"; var str3="111"; var str4=str1.concat(str2,str3); var str5=str2.concat(str1,str3); var str6=str3.concat(str1,str2); document.getElementById("str4").innerHTML ="str4=str1+str2+str3='"+str4+"'"; document.getElementById("str5").innerHTML ="str5=str2+str1+str3='"+str5+"'"; document.getElementById("str6").innerHTML ="str6=str3+str1+str2='"+str6+"'"; </script>
Rendering:
array The join() method
join() method is used to put all the elements in the array into a string. The elements in the array will be separated by the specified delimiter.
Syntax:
arrayObject.join(separator);
separator parameter: used to specify the separator style to be used, which can be omitted; if omitted, a comma is used as the separator.
Example: join() method to connect strings
<div class="demo "> <p>arr[0]="www"</p> <p>arr[1]=="php"</p> <p>arr[2]=="cn"</p> <p id="str1"></p> <p id="str2"></p> <p id="str3"></p> </div> <script type="text/javascript"> var arr=new Array(); arr=["www","php","cn"]; var str1=arr.join("."); var str2=arr.join("-"); var str3=arr.join(" "); document.getElementById("str1").innerHTML ="str1='"+str1+"'"; document.getElementById("str2").innerHTML ="str2='"+str2+"'"; document.getElementById("str3").innerHTML ="str3='"+str3+"'"; </script>
Rendering:
Summary: The above is this article The entire content, I hope it will be helpful to everyone's study.
【Recommended related video tutorials: JavaScript tutorial】
The above is the detailed content of How to connect strings in js. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use JS and Baidu Map to implement map pan function Baidu Map is a widely used map service platform, which is often used in web development to display geographical information, positioning and other functions. This article will introduce how to use JS and Baidu Map API to implement the map pan function, and provide specific code examples. 1. Preparation Before using Baidu Map API, you first need to apply for a developer account on Baidu Map Open Platform (http://lbsyun.baidu.com/) and create an application. Creation completed

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

Overview of how to use JS and Baidu Maps to implement map click event processing: In web development, it is often necessary to use map functions to display geographical location and geographical information. Click event processing on the map is a commonly used and important part of the map function. This article will introduce how to use JS and Baidu Map API to implement the click event processing function of the map, and give specific code examples. Steps: Import the API file of Baidu Map. First, import the file of Baidu Map API in the HTML file. This can be achieved through the following code:

How to use JS and Baidu Maps to implement the map heat map function Introduction: With the rapid development of the Internet and mobile devices, maps have become a common application scenario. As a visual display method, heat maps can help us understand the distribution of data more intuitively. This article will introduce how to use JS and Baidu Map API to implement the map heat map function, and provide specific code examples. Preparation work: Before starting, you need to prepare the following items: a Baidu developer account, create an application, and obtain the corresponding AP

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

Overview of how to use Python's join() function to merge strings: In Python, we often encounter situations where we need to merge multiple strings. Python provides a very convenient method join() to merge strings. This article will introduce how to use the join() function and provide some specific code examples. How to use the join() function: The join() function is a method of string. It accepts an iterable object as a parameter and adds the elements in the object to the
