Answer the question
In order to leave comments, you need to log in
How to implement a conditional search?
Task: from the list of inventory items, find if there is a sendItemName of them.
But for some reason the condition does not work correctly.
Here's how it works:
> There are 5 items in the inventory, it compares the name of the item with each of the 5 items
> ! But I get the result for the last thing answer = false (in our case), despite the fact that 2 things were found.
g_ItemName: [ 'Falchion Case' ]
sendItemName : Falchion Case
Item: Falchion Case found in inventory
Item: Falchion Case not found in inventory
Item: Falchion Case not found in inventory
Item: Falchion Case found in inventory
Item: Falchion Case not found in inventory
And I need, if there is at least one match then answer = true;
If nothing is found in any of the items, then answer = false;
How to implement this?
// Загрузка инвентаря с итемами
offers.loadMyInventory({appId: 730, contextId: 2}, function(err, items) {
var otvet = null;
// Поиск g_ItemName в items (которые есть в инвентаре)
g_ItemName.forEach(function(sendItemName) {
if (typeof sendItemName != 'undefined') {
for(var i = 0; i < items.length; i++){
// items[i].market_hash_name - находятся кучу разных вещей
// Задача: из списка вещей инвентаря найти есть ли sendItemName из них
if(sendItemName == items[i].market_hash_name){
console.log('Вещь: ' + sendItemName + ' найдена в инвентаре');
otvet = true;
}else{
console.log('Вещь: ' + sendItemName + ' не найдена в инвентаре');
otvet = false;
}
}
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question