JS String API

Property

PropertySyntax
string.length'abc'.length // 3

Method

MethodSyntaxReturn
String.fromCharCode()String.fromCharCode(65);"A"
-String.fromCharCode(65, 66, 67);"ABC"
String.fromCodePoint()String.fromCodePoint(65)"A"
-String.fromCodePoint(65, 66, 67);"ABC"
-String.fromCodePoint(0x2F804);"你"
charCodeAt()'abc'.charCodeAt(0)97
-'abc'.charCodeAt() // the default is 097
-'abc'.charCodeAt(3) // index out of rangeNaN
codePointAt()'abc'.codePointAt(0)97
-'abc'.codePointAt() // the default is 097
-'abc'.codePointAt(3) // index out of rangeundefined
endsWith()'abc'.endsWith('c')true
-'abc'.endsWith('b')false
-'abc'.endsWith('b', 2) // check [, 2) of 'abc'true
includes()'abc'.includes('b')true
-'abc'.includes('b', 2) // check [2, ) of 'abc'false
indexOf()'abca'.indexOf('a')0
-'abca'.indexOf('a', 1) // search in [1, )3
-'abc'.indexOf('z')-1
lastIndexOf()'abca'.lastIndexOf('a')3
-'abca'.lastIndexOf('a', 2) // search in [0, 2]0
-'abab'.lastIndexOf('ab', 2) // beginning of the match2
match()'ababa'.match(/a/g)['a', 'a', 'a']
-'abc'.match(/z/)null
padEnd()'abc'.padEnd(4)'abc '
-'abc'.padEnd(6, '.')'abc...'
padStart()'abc'.padStart(4)' abc'
-'abc'.padStart(6, '.')'...abc'
repeat()'abc'.repeat(3)'abcabcabc'
replace()'ababa'.replace(/a/g, 'z')'zbzbz'
-'ababa'.replace('a', 'z')'zbaba'
-'ababa'.replace(/a/g, x => x + x)'aabaabaa'
search()'abc'.search(/c/)2
-'abc'.search(/z/)-1
slice()'abc'.slice(1)'bc'
-'abc'.slice(1, 2) // [1, 2)'b'
-'abc'.slice(-1)'c'
-'abc'.slice(999)''
split()'abc'.split('')['a', 'b', 'c']
-'a b c'.split(' ')['a', 'b', 'c']
-'a b c'.split(' ', 2) // max length of array['a', 'b']
startsWith()'abc'.startsWith('a')true
-'abc'.startsWith('b')false
-'abc'.startsWith('b', 2) // check [2, ) of 'abc'true
toLowerCase()'Abc'.toLowerCase()'abc'
toUpperCase()'Abc'.toUpperCase()'ABC'
trim()' abc '.trim()'abc'
trimEnd()' abc '.trimEnd()' abc'
trimStart()' abc '.trimStart()'abc '
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值