there is 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} ]; 

this way 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]) } } } } 

how to make a condition

 if (all[k][i] == '3' && i == 'x' && all[k][i] == '1.5' && i == 'y') 
  • if (all[k][i] == '3' && i == 'x' && all[k][i] == '1.5' && i == 'y') not? - Alexey Shimansky
  • @ Alexey Shimansky, i == 'x' && i == 'y' ? - Grundy
  • @Grundy why? - Alexey Shimansky
  • @ Alexey Shimansky, well, you see the condition itself :-) - Grundy

1 answer 1

If you had in mind that you need to output elements with the key "x" and value "3" and elements with the key "y" and value "1.5" to the console, then you only need to replace one statement:

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