[问题探讨]js字符串(String)方法汇总

本文汇总了JavaScript中15个常用的字符串方法,包括concat(), endsWith(), includes(), indexOf(), lastIndexOf(), replace(), slice(), split(), toLowerCase(), toUpperCase(), match(), trim(), search(), charCodeAt()和fromCharCode(),详细介绍了它们的作用、语法、返回值和示例代码。" 53681930,5786066,HTML5 Canvas绘制圆弧详解,"['HTML5', 'canvas', '图形编程']
摘要由CSDN通过智能技术生成

需求:

js字符串(String)方法汇总

索引:

1,str.concat()
2,str.endsWith()
3,str.includes()
4,str.indexOf()
5,str.lastIndexOf()
6,str.replace()
7,str.slice()
8,str.split()
9,str.toLowerCase()
10,str.toUpperCase()
11,str.match()
12,str.trim()
13,str.search()
14,str.charCodeAt()
15,String.fromCharCode()

正文

1,str.concat()
(1)作用:将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回;
(2)语法:str.concat(str1,str2,str3…);
(3)语法解释:str,str1,str2,str3指代字符串;和+ +=操作符作用一样,建议优先使用+ +=;
(4)返回值:返回拼接后的字符串;
(5)示例代码:

const str='hello';
const res=str.concat(' world','!');
console.log(res);// hellow world!

2,str.endsWith()
(1)作用:判断当前字符串是否是以另外一个给定的子字符串“结尾”的;
(2)语法:str.endsWith(searchStr);
(3)语法解释:str被检索的原字符串,searchStr用来搜索的字符串;该方法大小写敏感;
(4)返回值:返回布尔值;
(5)示例代码:

const str='hello world!';
const res=str.endsWith('world!');
console.log(res);// true
const res1=str.endsWith('WORLD!');
console.log(res1);// false

3,str.includes()
(1)作用:判断一个字符串是否包含在另一个字符串中;
(2)语法:str.includes(searchStr);
(3)语法解释:str被检索的原字符串,searchStr用来搜索的字符串;该方法大小写敏感;
(4)返回值:返回布尔值;
(5)示例代码

const str='hello world!';
const res=str.includes('hello');
console.log(res);// true
const res1=str.includes('HELLO');
console.log(res1); // false

4,str.indexOf()
(1)作用:返回调用 String 对象中第一次出现的指定值的索引值࿱

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tom_wong666

码字不易,分享有功,期待赞赏!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值