An array of objects is given. Find the entered value in the array and output the sequence number of the array element with the key in which it is written. The key / value pair is not unique. Display information on all found, or a message about the lack of such.

If possible, advise how to solve this problem, and what you need to pay attention to. I would be extremely grateful.

    1 answer 1

    It seems decided. Sending an answer here.

    var array = [ { a1: 1 }, { a2: 2 }, { a3: 3 }, { a4: 4 }, { a5: 5 }, { a6: 6 }, { a7: 1 }, { a8: 3 }, { a9: 6 }, { a10: 2 }, { a11: 4 }, { a12: 6 } ]; var ahtung = true; for (var i = 0; i < array.length; i++) { for (key in array[i]) { if (array[i][key] === 3) { console.log("key is:" + key + " index is:" + i); ahtung = false; } } } if (ahtung) { console.log("Не найдено") } 
    • Only output i+1 to the console. - user218976
    • array [i] [key] === 'value' - right through this place I insert values - Tumanovskiy Andrew
    • What I mean is that for the second element it will output the value 1. "Find the entered value in the array and retrieve the sequence number" - 1 in this case is the index of the element of the array, and not the sequence number of the element. - user218976
    • I agree with this, of course. :) - Tumanovskiy Andrew 2:32 pm