1

I would like to get an array of the values of a Vue Object.

Object.values(obj) does not work as Vue translates object values to getters/setters: https://v2.vuejs.org/v2/guide/reactivity.html

2
  • What object? The whole Vue instance? Commented Apr 13, 2018 at 23:09
  • An object passed in as a Vue instnace's data Commented Apr 13, 2018 at 23:11

1 Answer 1

2

It does work (see below). Since you are looking for the whole data object, you can get it by Object.values(this.$data):

new Vue({
  el: '#app',
  data: {
    message: 'Open the console for a better view',
    person: {
    	name: {first_name: 'Alice', surname: 'Smith'},
      age: 15
    }
  },
  methods: {
    print() {
      console.log(Object.values(this.person));
      console.log(Object.values(this.person.name));

      console.log(Object.values(this.$data));
    }
  }
})
<script src="https://unpkg.com/vue"></script>

<div id="app">
  <p>{{ message }}</p>
  <button @click="print">print</button>
</div>

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.