js multiple key verification



  • json

    var all = [
        {'id': 1, 'x': 3, 'y': 1.5, z: 1.5, ves: 100, v: 0.15, 'norma': 'до 15', money: 0, 'money_holiday': 100,
            wait: 100, dostavka_time: 500, dostavka_nighttime: 1000, dostavka_fixnighttime: 1500},
        {'id': 2, 'x': 3, 'y': 1.7, z: 1.6, ves: 50, v: 0.15, 'norma': 'до 15', money: 300, 'money_holiday': 300,
            wait: 100, dostavka_time: 500, dostavka_nighttime: 1000, dostavka_fixnighttime: 1500},
        {'id': 3, 'x': 3, 'y': 1.7, z: 1.6, ves: 100, v: 0.4, 'norma': 'до 15', money: 300, 'money_holiday': 300,
            wait: 100, dostavka_time: 500, dostavka_nighttime: 1000, dostavka_fixnighttime: 1500}
    ];
    

    I can check one key.

    for (var k in all) {
        if (all.hasOwnProperty(k)) {
            for (var i in all[k]) {
                if (all[k].hasOwnProperty(i)) {
    
                        // alert("Key is " + k + ", value is" + array[k]);
    
                        if (all[k][i] == '3' && i == 'x') 
                           console.log(i, all[k])
            }
        }
    }
    

    }

    and how to make a condition

    if (all[k][i] == '3' && i == 'x' && all[k][i] == '1.5' && i == 'y')



  • If you mean that you need to put the "x" and "3" elements into the console and the "y" and "1.5" elements in it, it's just one operator to replace:

    if (all[k][i] == '3' && i == 'x' || all[k][i] == '1.5' && i == 'y') 
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2