I am using Angular 2 (latest version). I am trying to convert a JSON array i.e.
JavaScript
x
7
1
jsonObject = [
2
{"name": "Bill Gates"},
3
{"name": "Max Payne"},
4
{"name": "Trump"},
5
{"name": "Obama"}
6
];
7
to a string array and store just the value in i.e
JavaScript
1
2
1
arrayList: [string] = [''];
2
array. I tried to use Stringify method but no luck.
Advertisement
Answer
This should do the job:
JavaScript
1
4
1
names: string[] = jsonObject.map(person => person.name);
2
3
// => ["Bill Gates", "Max Payne", "Trump", "Obama"]
4