zoukankan      html  css  js  c++  java
  • JavaScript 中的forEach函数

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
      <script>
        function Person(name,age){
          this.name =name
          this.age = age
        }
        const per = new Person('孙悟空',25)
        const per1 = new Person('蜘蛛金',15)
        const per2 = new Person('猪八戒',24)
        const per3 = new Person('二郎神',8)
        const per4 = new Person('红孩儿',10)
        const per5 = new Person('杨戬',38)
        const arry = [per,per1,per2,per3,per4,per5]
        const newArry = []
        for(let i=0;i<arry.length;i++){
          if (arry[i].age>20){
            newArry.push(arry[i])
          }
        }
        // console.log(newArry);
        // forEach函数
        // 这种由我们创建的函数,但是不是由我们调用的函数叫做回调函数。
        arry.forEach(function(item){
    
          console.log('hello',item);
        })
      </script>
    </head>
    <body>
      
    </body>
    </html>
  • 相关阅读:
    玩家移动
    人物上线(激活玩家之后)
    map 玩家上线
    无锁的环形队列
    随笔
    std::bind
    如何查找文件中的schema约束
    myeclipse便捷导包方式
    21 求1+2!+3!+...+20!的和
    20 求出这个数列的前 20 项之和
  • 原文地址:https://www.cnblogs.com/ch2020/p/15711573.html
Copyright © 2011-2022 走看看