-6

我有一个数组

[
{
    "code": "MENU000014",
    "syskey": 2012071310410973022,
    "description": "Jiang Nan Dim Sum & Xiao Long Bao",
    "price": 0.0,
    "images": "kp-1.jpg",
    "imageb": "kp-1.jpg",
    "plucode": "",
    "style": "",
    "option": "",
    "stocksyskey": 0,
    "parentID": 0,
    "menutype": 1,
    "priceoperator": 0,
    "chineseDescription": ""
},
{
    "code": "MENU000019",
    "syskey": 2012071310571230035,
    "description": "Mix &  Match Multi-flavoured Xiao Long Bao",
    "price": 0.0,
    "images": "",
    "imageb": "",
    "plucode": "",
    "style": "",
    "option": "",
    "stocksyskey": 0,
    "parentID": 2012071310410973022,
    "menutype": 2,
    "priceoperator": 0,
    "chineseDescription": "雪碧é…香è‰é›ªç³•"
},
{
    "code": "MENU000020",
    "syskey": 2012071310571230036,
    "description": "Immediate preparation for Jiang Nan Speciality",
    "price": 0.0,
    "images": "",
    "imageb": "",
    "plucode": "",
    "style": "",
    "option": "",
    "stocksyskey": 0,
    "parentID": 2012071310410973022,
    "menutype": 2,
    "priceoperator": 0,
    "chineseDescription": "雪碧é…香è‰é›ª"
},
{
    "code": "MENU000002",
    "syskey": 2012071305045623001,
    "description": "Jiang Nan Appetizer",
    "price": 0.0,
    "images": "kp-4.jpg",
    "imageb": "kp-4.jpg",
    "plucode": "",
    "style": "",
    "option": "",
    "stocksyskey": 0,
    "parentID": 0,
    "menutype": 1,
    "priceoperator": 0,
    "chineseDescription": ""
},
{
    "code": "MENU000024",
    "syskey": 2012111809055570004,
    "description": "Soup",
    "price": 0.0,
    "images": "kp-5.jpg",
    "imageb": "kp-5.jpg",
    "plucode": "",
    "style": "",
    "option": "",
    "stocksyskey": 0,
    "parentID": 0,
    "menutype": 1,
    "priceoperator": 0,
    "chineseDescription": ""
},
{
    "code": "MENU000003",
    "syskey": 2012071305062942004,
    "description": "Double-Boiled Soup",
    "price": 0.0,
    "images": "0207_s.jpg",
    "imageb": "0207.jpg",
    "plucode": "",
    "style": "",
    "option": "",
    "stocksyskey": 0,
    "parentID": 2012111809055570004,
    "menutype": 2,
    "priceoperator": 0,
    "chineseDescription": "原盅炖汤"
},
{
    "code": "MENU000004",
    "syskey": 2012071305080136007,
    "description": "Soup & Thick Soup",
    "price": 0.0,
    "images": "kp-5.jpg",
    "imageb": "kp-5.jpg",
    "plucode": "",
    "style": "",
    "option": "",
    "stocksyskey": 0,
    "parentID": 2012111809055570004,
    "menutype": 2,
    "priceoperator": 0,
    "chineseDescription": "羹。生滚汤"
},
{
    "code": "MENU000022",
    "syskey": 2012111809055570002,
    "description": "Dishes",
    "price": 0.0,
    "images": "kp-6.jpg",
    "imageb": "kp-6.jpg",
    "plucode": "",
    "style": "",
    "option": "",
    "stocksyskey": 0,
    "parentID": 0,
    "menutype": 1,
    "priceoperator": 0,
    "chineseDescription": ""
},
{
    "code": "MENU000001",
    "syskey": 2012071304555547001,
    "description": "Pork",
    "price": 0.0,
    "images": "0403_s.jpg",
    "imageb": "0403.jpg",
    "plucode": "",
    "style": "",
    "option": "",
    "stocksyskey": 0,
    "parentID": 2012111809055570002,
    "menutype": 2,
    "priceoperator": 0,
    "chineseDescription": "肉类。猪"
},
{
    "code": "MENU000005",
    "syskey": 2012071306020332001,
    "description": "Prawn",
    "price": 0.0,
    "images": "0801_s.jpg",
    "imageb": "0801.jpg",
    "plucode": "",
    "style": "",
    "option": "",
    "stocksyskey": 0,
    "parentID": 2012111809055570002,
    "menutype": 2,
    "priceoperator": 0,
    "chineseDescription": "海鲜。虾"
},
{
    "code": "MENU000006",
    "syskey": 2012071306033011004,
    "description": "Beef",
    "price": 0.0,
    "images": "0503_s.jpg",
    "imageb": "0503.jpg",
    "plucode": "",
    "style": "",
    "option": "",
    "stocksyskey": 0,
    "parentID": 2012111809055570002,
    "menutype": 2,
    "priceoperator": 0,
    "chineseDescription": "肉类。牛"
},

我有一个数组2012071304555547001的值现在我怎样才能得到数组的索引而不是这个值的索引,而不是我需要数组的索引。jquery中需要此代码

4

1 回答 1

2

您是否尝试过基本for循环?但是,您需要将syskeyand转换parentID为字符串——这个数字对于(某些实现)JavaScript 来说太大了,无法处理。

var index = -1;
for (var i=0; i<arr.length; i++) {
    if (arr[i].parentID === "2012071304555547001") { // use strings, not numbers
        index = i;
    };
};
于 2013-03-06T15:54:31.153 回答