[[+content_image]]
K
K
kr_ilya2018-09-29 10:44:59
JavaScript
kr_ilya, 2018-09-29 10:44:59

How to select value by key from json array?

I'll ask a stupid question, but I really don't catch up with something.
There is a json file with such content Up to this point, I had to work only with the entire array.
[["EURUSD","25"],["GBPCAD","10"],["EURCAD","18"]]

$.getJSON('data_actm.json', function(resultpl) {
      var dp=[], labp = [];
         for(var item in resultpl){
labp.push(resultpl[item].slice(0,1).toString());
              dp.push(resmin[item].slice(1,2).toString());
          }
});

Now you need to select and add a value to the array by key. For example, for EURUSD, get 25 and put it in 2 different arrays. Tobish EURUSD to labp and 25 to dp

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
Alexander Pushkarev, 2018-09-29
@kr_ilya

$.getJSON('data_actm.json', (result) => {
    let dp   = [],
        labp = [];

    $.each(result, (key, value) => {
        labp.push(value[0]);
        dp.push(value[1]);
    });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question