zoukankan      html  css  js  c++  java
  • js-1

    数组操作

    this.arr.push('tzh','zmr');
    this.arr.pop();
    this.arr.shift();//删除开头的元素
    this.arr.unshift('tzh','zmr');//在开头添加元素
    this.arr.splice(2);//删除下标2以及之后的元素
    this.arr.splice(2,2);//删除下标从2开始的2个元素
    this.arr.splice(2,0,'lhy');//在下标为2的后面插入一个‘lhy’
    this.arr.splice(2,2,'lhy','zt');//从下标2开始的2个元素替换为'lhy' 'zt'
    Vue.set(this.arr,0,'sxy');
    
    
    var animals = [
      {name: 'Fluffykins', species: 'rabbit'},
      {name: 'Caro', species: 'dog'},
      {name: 'Hamilton', species: 'dog'},
      {name: 'harold', species: 'fish'}
    ]
    //回调函数执行arr.length次
    //过滤
    var newArr = arr.filter(function(x){
      return x === 'dog'
    })
    //映射
    var names = arr.map(function(x){
      return x*x
    })
    //求和
    arr.reduce(function(preVal,x){
      return preVal + x
    },0)

     

        var animals = [
          {name: 'Fluffykins', species: 'rabbit'},
          {name: 'Caro', species: 'dog'},
          {name: 'Hamilton', species: 'dog'},
          {name: 'harold', species: 'fish'}
        ]
        var isDog = function(animal){
          return animal.species === 'dog'
        }
        var dogs = animals.filter(isDog)
        var otherAnimals = animals.reject(isDog)
  • 相关阅读:
    最长什么什么子序列进阶(xym的hu测)
    樱花庄的宠物女孩AtCoder Grand Contest 015E
    樱花庄的宠物女孩AtCoder Grand Contest 015E
    boyne
    bzoj1001 [BeiJing2006]狼抓兔子
    95.自动注射
    94.文件bat脚本自删除
    93.下载器
    91.#pragma 详解
    91.生成ini文件并写入和读取ini文件
  • 原文地址:https://www.cnblogs.com/t1314/p/12670079.html
Copyright © 2011-2022 走看看