es6你不知道的小知识点

字符串


模板字符串:let message = `${name}你好啊`;

codePointA:返回ASCII值

fromCharCode:返回对应

includes():console.log("xiaoming".includes("om"));

startsWith():console.log("xiaoming".startsWith("om"));、

endsWith:console.log("xiaoming".endsWith("ming"));

repeat():console.log("xiaoming".repeat(3));

数组
扩展运算符(spread)是三个点(...) 将一个数组转为用逗号分隔的参数序列
let list = [3423,234,23545];
list.push(...["123","dfds","345234"])
类似数组的对象转为真正的数组
Array.from
let eles = Array.from(document.querySelectorAll(".item"));
Array.of方法用于将一组值,转换为数组
console.log(Array.of(4,3,42,42));
copyWithin(从哪开始替换数据,复制位置的起始点,结束点)
[1, 2, 3, 4, 5].copyWithin(0, 3)
// [4, 5, 3, 4, 5]
[1, 2, 3, 4, 5].copyWithin(0, 3, 4)
// [4, 2, 3, 4, 5]
find()
let res1 = list.find(function (value, index, arr) {
    return value>500;
});
findIndex()
let res2 = list.findIndex(function (value, index, arr) {
    return value>500;
});
fill(填充值,起始位置,长度)填充数组
console.log([111, 222,33].fill("tt", 0, 2));


Generator
Generator 函数是 ES6 提供的一种异步编程解决方案
function* generator() {
    yield ()=>{console.log("111")};
    yield ()=>{console.log("222")};
    return ()=>{console.log("333")};
}
let action = generator();
console.log(action.next());
action.next().value();
action.next().value();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值