Issue
I am using Angular 2 (latest version). I am trying to convert a JSON array i.e.
jsonObject = [
{"name": "Bill Gates"},
{"name": "Max Payne"},
{"name": "Trump"},
{"name": "Obama"}
];
to a string array and store just the value in i.e
arrayList: [string] = [''];
array. I tried to use Stringify method but no luck.
Solution
This should do the job:
names: string[] = jsonObject.map(person => person.name);
// => ["Bill Gates", "Max Payne", "Trump", "Obama"]
Answered By - seidme
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.