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))
  • 相关阅读:
    eclipse工具
    Tag
    JSP模版
    Eclipse断点调试
    JavaBean
    验证码设计
    在IE中提示404错误
    序列化与反序列化
    文件编码问题
    强类型,弱类型和推断类型
  • 原文地址:https://www.cnblogs.com/dalulu/p/9125291.html
Copyright © 2011-2022 走看看