Js 数组删除元素、json删除元素

        //数组var b=[1,2,3,4];
        b.splice(b.indexOf(2, 1))  //1,3,4

        //json
        var arrayId = [{ "id": 233, "name": "英语" }, { "id": 122, "name": "语文" }, { "id": 10, "name": "数学" }]
        for (var i = 0; i < arrayId.length; i++) {
            if (arrayId[i].id == item.id) {//item.id==122      
                arrayId.splice(i, 1)
            }
        }
        //{"id":233,"name":"英语"},{"id":10,"name":"数学"}

 

上一篇:字体移动


下一篇:发现splice的新大陆