Compare two multidimensional arrays in javascript

后端 未结 4 776
故里飘歌
故里飘歌 2021-01-23 09:18

I have two arrays:

var array_old = [{id:\"5436\", title:\"I Like you boy\"}, {id:\"5437\", title:\"Hello how are you\"}];
var array_new = [{id:\"5436\", title:\"         


        
4条回答
  •  逝去的感伤
    2021-01-23 09:31

    http://jsfiddle.net/tppiotrowski/VHb3Q/2/

    var array_old = [{
        id: "5436",
        title: "I Like you boy"},
    {
        id: "5437",
        title: "Hello how are you"}];
    var array_new = [{
        id: "5436",
        title: "I Like you boy"},
    {
        id: "1132",
        title: "I'm fine"}];
    
    $.each(array_old, function(old_index, old_obj) {
        var old_id = old_obj['id'];
        var found = false;
        $.each(array_new, function(new_index, new_obj) {
            if (new_obj['id'] == old_id) {
                found = true;
            }
        });
        if (!found) {
            alert(old_id + " does not exist in array_new");
        }
    });​
    

提交回复
热议问题