Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
Push data and key into array in vuejs

I have a array in data() :

data()  {
  return {
    list: [],
 }
},

methods: {
  pushData() {
     this.list.push({name:'yorn', age: 20});
  }
}

Now I want to push to the 'list' array of the following format, The key is info:

list [
     info [
     {
       name:yorn,
       age: 20
     }
  ]
 ]

I'm new to vuejs and javascript so I need everyone's help. Please give me your opinion. Thanks

over 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

I want to push to the 'list' array of the following format, The key is info

list: [ info: [ { name:yorn, age: 20 } ] ]

The above expected result is not a valid JSON. It should be like below :

list: [{
    info: [{
        name: yorn,
        age: 20
    }]
}]

Working Demo :

new Vue({
  el: '#app',
  data: {
    list: []
  },
  mounted() {
    this.pushData();
  },
  methods: {
    pushData() {
      this.list.push({info : [{name:'yorn', age: 20}] });
      // Or you can also use below one.
      // this.list[0].info.push({name:'yorn', age: 20});
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <div v-for="(obj, index) in list" :key="index">
    <p v-for="(item, i) in obj.info" :key="i">{{ item.name }}       </p>
  </div>
</div>

over 4 years ago · Juan Pablo Isaza Denunciar

0

You can simply use like below

pushData() {
 let data = { info : [{name:'yorn', age: 20}] }
 this.list.push(data);

}

Hope this is helpful. :-)

over 4 years ago · Juan Pablo Isaza Denunciar

0

Try altering the pushData method to have data parameter

pushData(data) {
 this.list.push(data);
}

Invoke the method

this.pushData({name: "john", age: 25});
over 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Asistente virtual