<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script type="text/javascript">
// let { foo, bar } = { foo: 'aaa', bar: 'bbb' };
// let { foo:bar } = { foo: 'aaa'};
// console.log(bar);
// console.log(foo);
// let obj = {p: ['hello', {y: 'world'}] };
// let {p: [x, { y }] } = obj;
// {p: [x, { y }] } = {p: ['hello', {y: 'world'}] }
// console.log(x);
// console.log(y);
// let obj = {p: ['hello', {y: 'world'}] };
// let {p: [x, { }] } = obj;
// console.log(x);
// console.log(y);
// let obj = {p: [{y: 'world'}] };
// let {p: [{ y }, x ] } = obj;
// {p: [{ y }, x ] } = {p: [{y: 'world'},] }
// console.log(x);
// console.log(y);
// let {a, b, ...rest} = {a: 10, b: 20, c: 30, d: 40};
// console.log(a);
// console.log(b);
// console.log(rest);
// let {a = 10, b = 5} = {a: 3};
// console.log(a);
// console.log(b);
// let {a: aa = 10, b: bb = 5} = {a: 3};
// console.log(aa);
// console.log(bb);
// ES6 之前判断字符串是否包含子串,用 indexOf 方法,ES6 新增了子串的识别方法。
// includes():返回布尔值,判断是否找到参数字符串。(重点)
// startsWith():返回布尔值,判断参数字符串是否在原字符串的头部。
// endsWith():返回布尔值,判断参数字符串是否在原字符串的尾部。
// 1.相同点:返回布尔值 查询到返回true, 没查找到返回false
// 以上三个方法都可以接受两个参数,需要搜索的字符串,和可选的搜索起始位置索引(从0开始)。
// let string = "apple,banana,orange";
// let a = string.includes("banana");
// // let a = string.includes("hello");
// console.log(a);
// let b = string.startsWith("apple");
// let c = string.endsWith("orange");
// console.log(b);
// console.log(c);
// let d = string.startsWith("a",0)
// console.log(d);
// repeat(number):返回新的字符串,表示将字符串重复指定次数返回。
// 1.如果参数是小数,向下取整
// 2.如果参数是 0 至 -1 之间的小数,会进行取整运算,0 至 -1 之间的小数取整得到 -0 ,等同于 repeat 零次
// 3.如果参数是 NaN,等同于 repeat 零次
// 4.如果参数是负数或者 Infinity ,会报错:
// 5.如果传入的参数是字符串,零次
// let str = "abc";
// let a = str.repeat(3);
// let a = str.repeat(-0.5);
// let a = str.repeat(NaN);
// let a = str.repeat(Infinity);
// let a = str.repeat("hello");
// console.log(str);
// console.log(a);
// padStart(总长度,"填充的字符串"):返回新的字符串,表示用参数字符串从头部(左侧)补全原字符串。
// padEnd(总长度,"填充的字符串"):返回新的字符串,表示用参数字符串从尾部(右侧)补全原字符串。
// 以上两个方法接受两个参数,第一个参数是指定生成的字符串的最小长度,
// 第二个参数是用来补全的字符串。如果没有指定第二个参数,默认用空格填充。
// let a = str.padStart(5,"x");
// let b = str.padEnd(5,"y");
// console.log(a);
// console.log(b);
// 模板字符串`` 带值${a}
// let a = 10;
// let str1 = "abcdadhsasdasdhjsdh"+a+
// +"jfdshjgsdfhjgsdfjd"
// console.log(str1);
// let str2 = `abcdadhsasdasdh${a}
// jsdh
// jfdshjgsdfhjgsdf
// jd`
// console.log(str2);
Number.isFinite(10);
console.log(Number.isFinite(10))
</script>
</html>
前端笔记es6
最新推荐文章于 2024-07-26 15:05:55 发布