如果我有这样的嵌套数组:

"localValues" : [
    {
        "localValId" : "e3rQACssGkfp9zsue",
        "localProductCode" : "271102502",
        "localMembersPrice" : 7814.090000000001,
        "localProductDescription" : "11R225 146/143L H DUN SP384 FM        TL",
        "fetPr" : "29.39",
        "invPrice" : "353.85"
    },
    {
        "localValId" : "NxtmZngRpGY56grkW",
        "localProductCode" : "290132910",
        "localMembersPrice" : "300",
        "localProductDescription" : "215/70R16 99S     DUN GRNDTRK ST20 BSWTL",
        "fetPr" : "",
        "invPrice" : "136.72"
    },
    {
        "localValId" : "WXLiCMJMixndtQtqZ",
        "localProductCode" : "271102502",
        "localMembersPrice" : "444",
        "localProductDescription" : "11R225 146/143L H DUN SP384 FM        TL",
        "fetPr" : "29.39",
        "invPrice" : "353.85"
    }];


有没有一种方法可以检查localValues数组中是否已存在新的localProductCode

谢谢。

最佳答案

你可以试试:

function isExisted(localValues, localProductCode) {
    for (var i = 0; i < localValues.length; ++i) {
        if (localValues[i].localProductCode == localProductCode) {
            return true;
        }
    }
    return false;
}

10-04 17:44