字符串的扩展 - 学习笔记

console.log("hello")
Unicode
console.log("\u0061")
console.log("\uD842\uDFB7")

// 字符串的遍历器接口
for (let codePoint of 'foo') {
    console.log(codePoint)
}
// String.fromCodePoint() 静态方法返回使用指定的代码点(Unicode编吗)序列创建的字符串
let text = String.fromCodePoint(0x20BB7)
console.log(text)
𠮷
for (let i = 0; i < text.length; i++) {
    console.log(text[i])
}
for (let i of text) {
    console.log(i)
}
// 上面代码中,字符串text只有一个字符,但是for循环会认为它包含两个字符(都不可打印),而for...of循环会正确识别出这一个字符。

// ``模板字符串 字符串
// 标签模板 它可以紧跟在一个函数名后面,该函数将被调用来处理这个模板字符串
console.log`hello`
//等同于
console.log(['hello'])


// 实例方法 indexOf() includes() startsWith() endsWith()

// indexOf()方法返回在数组中可以找到一个给定元素的第一个索引,如果不存在,则返回 - 1。
var array = [1, 3, 5, 7]
console.log(array.indexOf(1));
console.log(array.indexOf(3, 1));
// 第一个参数是要找的内容,第二个参数是从哪开始找,默认是0

// startsWith():返回布尔值,表示参数字符串是否在原字符串的头部。
// endsWith():返回布尔值,表示参数字符串是否在原字符串的尾部。
// includes():返回布尔值,表示是否找到了参数字符串。
let s = 'hello word'
console.log(s.includes('hello'))
console.log(s.startsWith('h'))
console.log(s.endsWith('d'))


// 实例方法 repeat()
// repeat方法返回一个新字符串,表示将原字符串重复n次。
console.log('hello'.repeat(2))

// 实例方法:trimStart(),trimEnd() 
// 消除字符串头部和尾部的空格  返回新的字符串


// bigInt  数后面加n
console.log(typeof 42n)
// bigint没有位数的限制
let p = 1n
for (let i = 1n; i <= 70n; i++) {
    p *= i
}
console.log(p)
// bigint函数 BigInt()
console.log(BigInt(123))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值