🌟 สวัสดีเพื่อน ๆ วันนี้แอดจะมาแชร์ 3 วิธี ง่าย ๆ ในการต่อ String ในภาษา JavaScript นั่นเอง !! มีวิธีไหน และมีรายละเอียดยังไง ไปดูกันเลยยย
.
1️⃣ ต่อ String ด้วยเครื่องหมายบวก (+)
.
const str1 = "Thailand is";
const str2 = "the land of compromise.";
const newStr = str1+' '+str2;
console.log(newStr);
.
📑 ผลลัพธ์
Thailand is the land of compromise.
.
2️⃣ String Template
เราสามารถสร้าง String Template ด้วยเครื่องหมาย Backticks และใส่ข้อความที่ต้องการให้แสดงลงในประโยคได้ เช่น
.
const Name = "Bang Lee";
const steTemp = `My name is ${Name}.`;
console.log(steTemp);
.
📑 ผลลัพธ์
My name is Bang Lee.
.
3️⃣ ใช้ฟังก์ชัน concat()
.
const string1 = "Me";
const string2 = "You";
const NewString = string1.concat(' & ',string2);
console.log(NewString);
.
📑 ผลลัพธ์
Me & You
*การใช้ concat() ต้องแน่ใจแล้วว่าตัวแปรทั้งสองเป็น String ไม่อย่างงั้นจะ Return TypeError ออกมานั่นเอง
.
ส่วนตัวแอดว่าใช้เครื่องหมายบวก ง่ายสุดละ แล้วเพื่อน ๆ ล่ะ ชอบวิธีไหนกันบ้างงง เมนต์มานะ 😆
.
borntoDev - 🦖 สร้างการเรียนรู้ที่ดีสำหรับสายไอทีในทุกวัน
同時也有10000部Youtube影片,追蹤數超過2,910的網紅コバにゃんチャンネル,也在其Youtube影片中提到,...
「javascript string concat」的推薦目錄:
- 關於javascript string concat 在 BorntoDev Facebook 的最佳貼文
- 關於javascript string concat 在 コバにゃんチャンネル Youtube 的最佳解答
- 關於javascript string concat 在 大象中醫 Youtube 的最佳解答
- 關於javascript string concat 在 大象中醫 Youtube 的最佳解答
- 關於javascript string concat 在 Top 3 Practical Ways to Perform Javascript String Concatenation 的評價
- 關於javascript string concat 在 JS strings "+" vs concat method [duplicate] - Stack Overflow 的評價
- 關於javascript string concat 在 concat method | String Object In JavaScript - YouTube 的評價
- 關於javascript string concat 在 13 How to Concatenate Strings in JavaScript - YouTube 的評價
- 關於javascript string concat 在 airbnb/javascript: JavaScript Style Guide - GitHub 的評價
- 關於javascript string concat 在 How to append value of column with double quotes (add ... 的評價
javascript string concat 在 JS strings "+" vs concat method [duplicate] - Stack Overflow 的推薦與評價
... <看更多>
javascript string concat 在 concat method | String Object In JavaScript - YouTube 的推薦與評價

concat method | String Object In JavaScript ... 1K views 10 months ago All String Methods And Properties | String Object In JavaScript. ... <看更多>
javascript string concat 在 Top 3 Practical Ways to Perform Javascript String Concatenation 的推薦與評價
Top 3 Practical Ways to Perform Javascript String Concatenation · Use the concat() method · Use the + and += operators · Use the template literals ... ... <看更多>