A
A
Alisa942019-01-15 17:07:04
JavaScript
Alisa94, 2019-01-15 17:07:04

How to pass name and from JSON to JS object?

Help kindly. I have this situation, there is a JSON file with content

[
  { "name": "foo",
    "status": "success" }, {
    "name": "bar",
    "status": "success"}, {
    "name": "biz",
    "status": "success"
  }
]

It is necessary to transfer all names to the JS object.
Any help would be helpful, thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Proskurin, 2019-01-15
@Alisa94

I don’t know what kind of object it is, but it’s easy into an array.

let str = `[
  { "name": "foo",
    "status": "success" }, {
    "name": "bar",
    "status": "success"}, {
    "name": "biz",
    "status": "success"
  }
]`;
let obj = JSON.parse(str);
let list = obj.map(x => x.name);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question