zoukankan      html  css  js  c++  java
  • js删除数组中某一项,splice()

    var id = '3'
    var tagList = [{"parentTagId":"1","parentTagName":"学校","childTagId":"3","childTagName":"高中"},
                    {"parentTagId":"1","parentTagName":"学校","childTagId":"4","childTagName":"初中"}]
    for(var i = 0; i < tagList.length; i++){
        if(tagList[i].childTagId === id){
            tagList.splice(i,1);
        }
    }
    console.log(JSON.stringify(tagList))

    或者直接是哪对象过来也行,一样的方法:

    var obj = {
        parentTagId : '1',
        parentTagName:"学校",
        childTagId: '3',
        childTagName:"高中"
    }
    var tagList = [{"parentTagId":"1","parentTagName":"学校","childTagId":"3","childTagName":"高中"},
                    {"parentTagId":"1","parentTagName":"学校","childTagId":"4","childTagName":"初中"}]
    for(var i = 0; i < tagList.length; i++){
        if(tagList[i].childTagId === obj.childTagId){
            tagList.splice(i,1);
        }
    }
    console.log(JSON.stringify(tagList))
  • 相关阅读:
    vue学习
    BBS登录注册技术点归纳
    BBS项目模态框的使用
    django后台管理系统
    java 之 jsp简介
    http 之 CORS简介
    web 之 session
    linux 之学习路线
    Ubuntu 之 win10更新ubuntu启动项消失
    Web 之 Cookie
  • 原文地址:https://www.cnblogs.com/dalulu/p/9125291.html
Copyright © 2011-2022 走看看