How to get only the 1st appearing key when having multiple duplicate values in nested object – JavaScript

I have the following JavaScript nested object:

    let menu = {
    vegetarian: {
        plainPizza: 100,
        redChilliPizza: 150,
        cheesePizza: 200,
        capsicumPizza: 160,
        onionPizza: 200
    nonVegetarian: {
        supremeMeatPizza: 100,
        meatPizza: 130,
        meatLoversPizza: 160,
        chickenPizza: 200,
        chilliMeatPizza: 200

let minimumPrice = 100;
let maximumPrice = 200;

I need to show Pizzas between the given price range but want to show the Pizza only that is coming 1st and having price same for other pizzas. For example for a Pizza of Rs. 100 I just want to show only ‘plainPizza’, not others in my results. And same for others too. I got the price range results but are with all Pizza. Here’s my code below:

    function searchUsingPriceRangeFromMenu(mainObject, minimumPrice, maximumPrice) {
    for (let key in mainObject) {
        let arrOfPriceRangeKeys = [];
        if (typeof mainObject[key] !== "object" && mainObject[key] >= minimumPrice && mainObject[key] <= maximumPrice) {
            arrOfPriceRangeKeys = key;
            document.write(arrOfPriceRangeKeys + "<br>")
        } else {
            if (typeof mainObject[key] === "object") {
                searchUsingPriceRangeFromMenu(mainObject[key], minimumPrice, maximumPrice, arrOfPriceRangeKeys)

    } return;
searchUsingPriceRangeFromMenu(menu, minimumPrice, maximumPrice);

My Results:


So please tell me what I need to do is and where? All I want to end up with as following:


help me.

145 thoughts on “How to get only the 1st appearing key when having multiple duplicate values in nested object – JavaScript”

  1. i need loan today, i need loan embassy finder. i need loan to pay off debt i need loan i own my home outright and need a loan i need a loan no job bad credit, cash advance loans contact number, cash advance, cash advance online, payday advance loans without bank account. Investment lending to economics, accepts deposits.

  2. pharmacie de garde marseille 6 octobre pharmacie ouverte h24 paris pharmacie becker monteux 84 , medicaments yeux fatigues pharmacie annecy rocade , pharmacie beauvais voisinlieu medicaments traduction therapie comportementale et cognitive le mans Clarithromycin prix France, Achat Clarithromycin bon marchГ© [url=–acheter-clarithromycin-prix-france/08RRz/#]Achat Clarithromycin bon marchГ©[/url] Clarithromycin prix sans ordonnance Clarithromycin France sans ordonnance. pharmacie avenue stalingrad argenteuil therapie cognitivo comportementale quebec Baricitinib en pharmacie Canada, Acheter Olumiant en pharmacie Canada [url=]Ou acheter du Olumiant 4mg[/url] Cherche Olumiant moins cher Olumiant sans ordonnance prix. pharmacie de garde bailly therapie cognitivo-comportementale gratuite , therapies for autism pharmacie fouassier bourges horaires Monurol achat en ligne Belgique, Fosfomycine prix sans ordonnance [url=]Fosfomycine sans ordonnance Belgique[/url] Vente Fosfomycine sans ordonnance Fosfomycine sans ordonnance prix. pharmacie a amiens pharmacie auchan dunkerque .


Leave a Comment