The task is this: you need to "return the pedigree" in 2 objects, i.e.
There are 2 objects obj1 and obj2 and their properties:

 obj1["Π–Π΅Π½Ρ‰ΠΈΠ½Π°ΠΌ"] = 'кросовки,Ρ‚ΠΎΠΏΡ‹'; obj1["ΠœΡƒΠΆΡ‡ΠΈΠ½Π°ΠΌ"] = 'ΡˆΠΎΡ€Ρ‚Ρ‹,ΠΌΠ°ΠΉΠΊΠΈ'; obj2["кросовки"] = 'adidas,puma'; obj2["Ρ‚ΠΎΠΏΡ‹"] = '...'; ... 

Now let's say you need to find puma and the function should return кросовки -> Π–Π΅Π½Ρ‰ΠΈΠ½Π°ΠΌ

  • Maybe it is better to alter the structure of objects, if possible? - Stepan Kasyanenko
  • @Stepan Kasyanenko unfortunately not. Objects are used not only for this - Aziret Kadykeev
  • one
    Very strange task ... What did you try to do? Are there any ideas? - Stepan Kasyanenko

2 answers 2

In the search function, you pass in the array as many objects as you wish, and the value from which you want to build the chain will be searched. Objects must be transferred in the order in which the search must be accepted. At the exit, get an array with the keys where the entries were found.

 const obj1 = {}; const obj2 = {}; obj1["Π–Π΅Π½Ρ‰ΠΈΠ½Π°ΠΌ"] = 'кросовки,Ρ‚ΠΎΠΏΡ‹'; obj1["ΠœΡƒΠΆΡ‡ΠΈΠ½Π°ΠΌ"] = 'ΡˆΠΎΡ€Ρ‚Ρ‹,ΠΌΠ°ΠΉΠΊΠΈ'; obj2["кросовки"] = 'adidas,puma'; const search = (arrObj, target) => arrObj.reduce( (prev, curr, index) => [ ...prev, Object .keys(curr) .find(key => curr[key].includes(prev[index])) ], [target] ) window.document.getElementById('result').innerHTML = search([obj2, obj1], "puma").join('->') 
 <div id="result"></div> 

ps: before using in production you need to finish handling exceptional situations;)

    Try this))

     let obj1 = { "Π–Π΅Π½Ρ‰ΠΈΠ½Π°ΠΌ": 'кросовки,Ρ‚ΠΎΠΏΡ‹', "ΠœΡƒΠΆΡ‡ΠΈΠ½Π°ΠΌ": 'ΡˆΠΎΡ€Ρ‚Ρ‹,ΠΌΠ°ΠΉΠΊΠΈ' }; let obj2 = { "кросовки": 'adidas,puma', "Ρ‚ΠΎΠΏΡ‹": 'nike,guchi', "ΡˆΠΎΡ€Ρ‚Ρ‹": 'nike' }; $('#click_me').click(function() { let name = $('#company').val(); let keys2 = []; $.each(obj2, function( key, value ) { if (value.indexOf(name) !== -1) { keys2.push(key); } }); $.each(keys2, function( key2, value2 ) { $.each(obj1, function( key1, value1 ) { if (value1.indexOf(value2) !== -1) { console.log(value2 + ' -> ' + key1); } }); }); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input placeholder="Π’Π²Π΅Π΄ΠΈΡ‚Π΅ Ρ„ΠΈΡ€ΠΌΡƒ" type="text" id="company"></input> <button id="click_me">Click ME</button> 

    • A little bit does not meet the condition. There must be кросовки -> Π–Π΅Π½Ρ‰ΠΈΠ½Π°ΠΌ - Stepan Kasyanenko
    • @StepanKasyanenko Amended))))))))) - Ilia Brykin
    • But it still goes out and Ρ‚ΠΎΠΏΡ‹ -> Π–Π΅Π½Ρ‰ΠΈΠ½Π°ΠΌ . And since we have sneakers, we only need sneakers кросовки -> Π–Π΅Π½Ρ‰ΠΈΠ½Π°ΠΌ ! Or I did not understand the task o_O - Stepan Kasyanenko
    • I just improved the task a bit, because there may be different things from the same company. Therefore, Puma stands for two categories. let obj2 = {"sneakers": 'adidas, puma', "tops": 'nike, puma', "shorts": 'nike'}; If you change the value of the property "tops", then vadast only one value. - Ilia Brykin
    • Did the questioner write somewhere that he wants it done through jQuery? Please, if you are not asked to do this, then do not write through jQuery. - Bharata