fengchuanyu 3 月之前
父節點
當前提交
8406bb6e49
共有 3 個文件被更改,包括 158 次插入0 次删除
  1. 52 0
      6_ES6/11_ES新增遍历.html
  2. 39 0
      6_ES6/12_数组新增方法.html
  3. 67 0
      6_ES6/13_扩展运算符.html

+ 52 - 0
6_ES6/11_ES新增遍历.html

@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script>
+        let arr = [1,2,3,4,5,6,7,8,9];
+        // find() 方法返回通过测试(函数内判断)的数组的第一个元素的值。否则返回 undefined。
+        // let res = arr.find((item,index,_arr)=>{
+        //     // console.log(item,index,_arr)
+        //     console.log("item="+item);
+
+        //     return item > 6;
+        //     // if(item > 6){
+        //     //     return true
+        //     // }else{
+        //     //     return false
+        //     // }
+        // })
+        // console.log(res);
+        // findIndex() 方法返回传入一个测试条件(函数)符合条件的数组第一个元素位置。否则返回-1。
+        // let res = arr.findIndex((item,index,_arr)=>{
+        //     return item > 6;
+        // })
+        // console.log(res);
+        // for of 遍历也曾为迭代器 
+        // for(let val of arr){
+        //     console.log(val);
+        // }
+        // for of 中可以通过给数组加上 .keys() 返回索引
+        // for(let val of arr.keys()){
+        //     console.log(val);
+        // }
+        // for of 中可以通过给数组加上 .values() 返回值
+        // for(let val of arr.values()){
+        //     console.log(val);
+        // }
+        // for of 中可以通过给数组加上 .entries() 返回索引和值
+        // for(let val of arr.entries()){
+        //     let key = val[0];
+        //     let value = val[1];
+        //     console.log(key,value);
+        // }
+        for(let [key,value] of arr.entries()){
+            console.log(key,value);
+        }
+    </script>
+</body>
+</html>

+ 39 - 0
6_ES6/12_数组新增方法.html

@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <ul>
+        <li>1</li>
+        <li>2</li>
+        <li>3</li>
+        <li>4</li>
+        <li>5</li>
+        <li>6</li>
+    </ul>
+    <script>
+        let aLi = document.getElementsByTagName('li');
+        // Array.from 将类数组/伪数组转化为数组
+        // let aLi2 = Array.from(aLi);
+        // console.log(aLi);
+        // console.log(aLi2);
+        // aLi2.forEach(function(item,index){
+        //     item.innerText += "a";
+        // })
+
+        // let a = 1;
+        // let b = "hello";
+        // let c = true;
+        // let d = {val:"你好"}
+        // // Array.of 将一组值转化为数组
+        // let arr = Array.of(a,b,c,d,aLi[0]);
+        // console.log(arr);
+        let arr = new Array(1,2,3,4,5);
+        arr.fill("a",0,3);
+        console.log(arr)
+    </script>
+</body>
+</html>

+ 67 - 0
6_ES6/13_扩展运算符.html

@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <ul>
+        <li>1</li>
+        <li>2</li>
+        <li>3</li>
+        <li>4</li>
+        <li>5</li>
+        <li>6</li>
+    </ul>
+    <script>
+        let aLi = document.getElementsByTagName('li');
+        // let arr = [1,2,3,4,5,6];
+        // let arr2 = arr;
+        // arr[0] = 100;
+        // console.log(arr2);
+
+        // ... 扩展运算符 
+        // let arr = [1,2,3,4,5,6];
+        // let arr2 = [...arr];
+        // arr[0] = 100;
+        // console.log(arr2);
+
+        // let liList = [...aLi];
+        // console.log(liList);
+
+        // let arr1 = [1,2,3,4,5]
+        // let arr2 = [6,7,8,9,10]
+        // let arr3 = arr1.concat(arr2);
+        // console.log(arr3);
+        // let arr3 = [...arr1,...arr2];
+        // console.log(arr3);
+
+        // function foo(...arg){
+        //     console.log(arg);
+        // }
+        // foo(1,2,3,4)
+
+
+        // ...arg 在以下情况中 代表剩余参数
+        // function foo(a,b,...arg){
+        //     console.log(arg);
+        // }
+        // foo(1,2,3,4)
+
+        let obj = {
+            name:'张三',
+            age:18,
+            sex:'男'
+        }
+        let obj3 = {
+            school:"黑大"
+        }
+        let obj2 = {...obj,...obj3};
+        obj.name = '李四';
+        console.log(obj2);
+        
+        
+    </script>
+</body>
+</html>