Задать вопрос
@cok23

Почему выдает ошибку в js?

0: {BASKET_ID: 338466, BASE_PRICE: 2700, PRICE: 1350, DISCOUNT: 1350}
1: {BASKET_ID: 338467, BASE_PRICE: 2800, PRICE: 1400, DISCOUNT: 1400}
2: {BASKET_ID: 338468, BASE_PRICE: 2800, PRICE: 2800, DISCOUNT: 0}

for (index = 0; index <= data.length; ++index) {
console.log(data);
var BASKET_ID = data[index]['BASE_PRICE'];
}
выдает ошибку basket/?clear_cache=Y:2165 Uncaught TypeError: Cannot read properties of undefined (reading 'BASE_PRICE')
at Object.success (basket/?clear_cache=Y:2165:61)
at c (jquery-3.6.0.min.js:2:28327)
at Object.fireWith [as resolveWith] (jquery-3.6.0.min.js:2:29072)
at l (jquery-3.6.0.min.js:2:79901)
at XMLHttpRequest. (jquery-3.6.0.min.js:2:82355)
подскажите что не так ?

for (index = 0; index <= data.length; ++index) {
console.log(data[index]['BASKET_ID']);
}
без присвоения переменной

338466
338467
338468
Uncaught TypeError: Cannot read properties of undefined (reading 'BASKET_ID')
at Object.success (basket/?clear_cache=Y:2164:56)
at c (jquery-3.6.0.min.js:2:28327)
at Object.fireWith [as resolveWith] (jquery-3.6.0.min.js:2:29072)
at l (jquery-3.6.0.min.js:2:79901)
at XMLHttpRequest. (jquery-3.6.0.min.js:2:82355)
  • Вопрос задан
  • 47 просмотров
Подписаться 1 Средний 5 комментариев
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы