Сообщение от Dmitry1988
|
Обозначение позиции товара a,b,c,d,e.
|
let objJson = {
"a" : {
"name" : "coca-cola",
"cost" : "10",
"description" : "описание товара 1",
"image" : "img/Coca-Cola.jpg",
"type" : "drink",
"link" : "46147110",
"pos" : "1"
},
"b" : {
"name" : "кофе",
"cost" : "10",
"description" : "описание товара 2",
"image" : "img/cofe.jpg",
"link" : "goods/tb-2.html",
"type" : "drink",
"pos" : "46147111"
},
"c" : {
"name" : "чипсы",
"cost" : "30",
"description" : "описание товара 3",
"image" : "img/chips.jpeg",
"link" : "46147112",
"type" : "snack",
"pos" : "3"
},
"d" : {
"name" : "сендвич",
"cost" : "40",
"description" : "описание товара 4",
"image" : "img/sandvich.png",
"link" : "46147113",
"type" : "pie",
"pos" : "4"
},
"e" : {
"name" : "coca-cola",
"cost" : "10",
"description" : "описание товара 1",
"image" : "img/Coca-Cola.jpg",
"type" : "drink",
"link" : "46147114",
"pos" : "5"
}
};
let barcode = "46147110";
function findId(barcode)
{
for(let [id, obj] of Object.entries(objJson)){
if(obj.link == barcode) return id
}
}
let id = findId(barcode);
alert(id);