Skip to content

How to make an array of objects from object array in vueJs?

I have an Object array which is following enter image description here

But, I need to show

  • email: Email muss eine …..
  • phone: Telefonnummer ist …

How can I do this in javascript? Actually I need to use this in VueJs.

Answer

From the screenshot you are receiving this from props so we can do this in the template:

<template>
  <div class="errors">
    {{  failureReasons.email ? failureReasons.email[0] }}
  </div>
</template>

If you would like to get all the errors into a single array (e.g. ['Email mus...', 'Telefon ...']) you can do:

<template>
  <ul>
   <li v-for="error in Object.keys(failureReasons).map(key => failureReasons[key][0])"> {{ error}} </li>
  <ul>
</template>