1

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"];

1 Answer 1

8

You can do that in a single line like this:

this.users = this.users.map(user => user.name);
Sign up to request clarification or add additional context in comments.

2 Comments

Its Working...Sir
Glad to hear that @SanchitMahajan :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.