zoukankan      html  css  js  c++  java
  • es6数组新特性

    数组循环属性:for,map,filter,foreach

    结论:除了for,其他都不能通过return false,终止循环

    代码

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport"
            content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>Document</title>
    </head>
    <body>
    <script>
      var data = [1,2,3,4,5]
      var arr = [
        {text: '张三', age: 9},
        {text: '李四', age: 20},
        {text: '王五', age: 20},
        {text: '赵六', age: 20}
      ]
      function a() {
        for(var i=0; i<5; i++) {
          console.log(i);
          return false
        }
      }
      function b() {
        data.filter(v => {
          console.log(v)
          return false
          console.log('哈哈')
        })
      }
      function c() {
        return arr.map((v, k) => {
          if (v.age>10) {
            return v.text
          } else {
            return ''
          }
        })
      }
      function d() {
        arr.forEach((v, k) => {
          console.log(v)
          return false
        })
      }
    
      console.log(a())
      console.log('a---------------------------')
      console.log(b())
      console.log('b---------------------------')
      console.log(c())
      console.log('c---------------------------')
      console.log(d())
      console.log('d---------------------------')
      console.log('for之后');
    </script>
    </body>
    </html>

    结果如图:

    参考:http://es6.ruanyifeng.com/

  • 相关阅读:
    使用shc加密bash脚本程序
    shell加密工具shc的安装和使用
    cgi程序报 Premature end of script headers:
    gearmand安装过程
    解决Gearman 报sqlite3错误
    gearman安装实录
    PHP APC安装与使用
    在Centos上面用yum不能安装redis的朋友看过来
    CentOS 5
    CentOS安装配置MongoDB
  • 原文地址:https://www.cnblogs.com/zph666/p/7773767.html
Copyright © 2011-2022 走看看