Answer the question
In order to leave comments, you need to log in
How to execute a condition if there is at least one true condition in the JSON array?
The array looks something like this:
[{"ui_bid":"1451245124","ui_id":"124161616"}{"ui_bid":"124124124","ui_id":"123124"}{"ui_bid":"0","ui_id":"12123124"}{"ui_bid":"0","ui_id":"1231242352"}]
function Request() {
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var responseBody = xhr.responseText;
var event = JSON.parse(responseBody, function(key, value) {
if (key == 'ui_bid')
return value;
if (value != '0') {
xhr.open('GET', 'тут url для запроса', false);
xhr.send();
setTimeout(UpdateInventory, 60000);
}
})
}};
xhr.open('GET', 'тут тоже url для запроса', false);
xhr.send();
}
Request();
Answer the question
In order to leave comments, you need to log in
I would write like this, everything works: jsfiddle.net/oay5jcna
var data = JSON.parse('[{"ui_bid":"1451245124","ui_id":"124161616"},{"ui_bid":"124124124","ui_id":"123124"},{"ui_bid":"0","ui_id":"12123124"},{"ui_bid":"0","ui_id":"1231242352"}]');
data.forEach(function (item, value) {
var bid = +item.ui_bid;
if (bid) {
console.log(value); // Вот тут ваш запрос
}
});
var acess = array.some(function(e){
return +e.ui_bid === 0;
});
//acess = true, если хоть 1 из ui_bid равен 0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question