-2

In vue my data looks like this:

data: {
    messages: []
  }

But the data returned from the api looks like this (array of objects)

messages: Array(1)
 0: Object
  message: "qwerqwer"

How do I convert a array of objects into an array of arrays?

2

1 Answer 1

1

This will do exactly what you want it to do, but you should try to understand and not just blind copy it:

messages = messages.map(
    function(message){
        return message.message;
    }
);

Read about Array.prototype.map()

Sign up to request clarification or add additional context in comments.

Comments

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.