For my affiliate site I import a XML feed and then use the XML2JSON function to convert this to a JSON object. It looks like this:
{products: {…}}
products:
product: Array(6510)
[0 … 99]
0:
aw_deep_link: "https://www.awin1.com/pclick.php?p=21982055441&a=852189&m=12893"
aw_image_url: "https://images2.productserve.com/?w=200&h=200&bg=white&trim=5&t=letterbox&url=ssl%3Awww.spellenrijk.nl%2Fresize%2F18111_3wy7yf3_5638761353075.jpg%2F300%2F300%2FTrue%2Fblackfire-boardgame-sleeves-square-72x73mm.jpg&feedId=25919&k=1ab7328112246a7b95251ed47642ace5169a9583"
aw_product_id: "21982055441"
category_id: "0"
category_name: ""
currency: "EUR"
data_feed_id: "25919"
delivery_cost: "3,99"
description: "Bordspel sleeves met een afmeting van 72 x 73 mm. Deze verpakking bevat 100 sleeves. Geschikt voor: Catan card game, Anno 1701 card game, Summertime, Powergrid, Funkenschlag vele andere spellen. - Thickness 40 microns - Extra high clarity - Prevents bent corners - Prevents scratches - Perfect fitting for a lot of board game cards - Durable material for long gameplay - Acid free - no PVC"
display_price: "EUR2.95"
language: ""
last_updated: ""
merchant_category: "Spelonderdelen"
merchant_deep_link: "https://www.spellenrijk.nl/artikel/20343/blackfire-boardgame-sleeves-square-72x73mm.html?utm_source=affiliate4you-NL&utm_campaign=datafeed"
merchant_id: "12893"
merchant_image_url: "https://www.spellenrijk.nl/resize/18111_3wy7yf3_5638761353075.jpg/300/300/True/blackfire-boardgame-sleeves-square-72x73mm.jpg"
merchant_name: "Spellenrijk.nl NL - FamilyBlend"
merchant_product_id: "20343"
product_name: "Blackfire Boardgame Sleeves - Square (72x73mm)"
search_price: "2.95"
store_price: "2,95"
I want to get the price (store_price) from this JSON object and show this on my HTML site. Used the find and findIndex function but I constantly get a -1 returned.
The code I am using (based on this answer: Find object by id in an array of JavaScript objects):
var product = "Blackfire Boardgame Sleeves - Square (72x73mm)";
var price = data.findIndex(x => x.products.product.product_name === product)