S
S
semki0962016-03-21 09:58:41
JavaScript
semki096, 2016-03-21 09:58:41

How to convert json array?

Please tell me how the array of the form

[{"id":"99","parent_id":"105},{"id":"13","parent_id":"305"}]

convert to [99, 13]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2016-03-21
@semki096

var a = [{"id":"99","parent_id":"105"},{"id":"13","parent_id":"305"}].map(
  function (item) {
    return +item.id;
  }
);

J
JohnFrolov, 2016-03-23
@JohnFrolov

need more crutches

function getValuesByKey(array, key) {
    const res = array.map((item) => {
        return +item[key] || 0; 
    });
    return res || [];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question