Reputation: 315
In Ionic 3, I am fetching an array of objects in the controller. But it is not useful for me. So I want to convert array of objects to array of strings.. I am getting following data in controller.
this.users = [{"id":1,"name":"US"},{"id":2,"name":"UK"}]
But I want the result below:
this.users = ["US", "UK"];
Upvotes: 1
Views: 4600
Reputation: 44659
You can do that in a single line like this:
this.users = this.users.map(user => user.name);
Upvotes: 8