zoukankan      html  css  js  c++  java
  • javascript基础

    JavaScript数组操作:

    1、如何根据id找到删除这项的索引
    2、直接调用数组的splice方法
    this.list.some((item,i) => {
             if (item.id = id)
                  this.list.splice(i, 1)
       return true;
    })

      

              var index = this.list.findIndex(item => {
                if (item.id == id)
                  return true
              })
              console.log(index)
              this.list.splice(index, 1)
    

     

             // 之前v-for中的数据都是从list中的数据直接渲染过来的
            // 现在,自定义一个方法 Search 方法,同事,把 所有的关键字,通过传参的形式传递给Search方法
            // 把符合条件的数据组成一个新数组,返回
            Search(keywords) {
              var newList = []
              // this.list.forEach(item => {
              //   if (item.name.indexOf(keywords) != -1) {
              //     newList.push(item)
              //   }
              // })
              this.list.filter(item=>{

    //ES6中提供的字符串是否包含另一字符串includes,写法:string.prototype.includes('要包含的字符串'),如果包含,返回true,否则false if (item.name.includes(keywords)) { newList.push(item) } }) return newList }

      

     

  • 相关阅读:
    简析IGRP
    unicode字符集查找
    中国移动建成全球最大软交换网络 适合向3G过渡
    寻找端口与进程的关联
    framerelay
    网络工程师的素质
    E1通信的基础知识
    Indy UDP端口冲突解决
    『软考』接入网的分类
    随便写写。。
  • 原文地址:https://www.cnblogs.com/CelonY/p/12561953.html
Copyright © 2011-2022 走看看