O
O
Olesya_v2021-05-25 23:32:53
JavaScript
Olesya_v, 2021-05-25 23:32:53

Iterating over an object and deriving values?

There is an object:

var jsonObj = new Object({
                "A0OA1": {
                    "prod1": "308 - 23 µm",
                    "prod2": "555 - 12-15 µm",
                    "prod3": "333 - 15-17 µm"
                },
                "A0OA2": {
                    "prod1": "308 - 23 µm",
                    "prod2": "555 - 12-15 µm",
                    "prod3": "333 - 15-17 µm"
                },
                "A0OA3": {
                    "prod1": "308 - 30 µm",
                    "prod2": "555 - 15-17 µm",
                    "prod3": "333 - 17 µm"
                },
 });

Есть кнопки , условно 
<button data-key="A0OA1">button1</button>
<button data-key="A0OA2">button2</button>
<button data-key="A0OA3">button3</button>


when clicked, I get the value of the data-key attribute, which is also the desired key
, and try to display the values:

$('button').click(function (event) {
    var dataK= $(this).attr("data-key");

  for (var [key, value] of Object.entries(jjsonObj.dataK)) {
                 console.log(value);
  }
});


How to output values?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question