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

144
Vistas
VueJS - Push an object to an array of objects inside an async function

I'm currently working on a Vue 2 project, and I have to push an object from outside the async function scoop. Here's the code in subject below :

async getData() {
  return [
  {
    id: "1",
    name: "Slim",
    age: 5,
    location: 1500,
    breed: 500,
  },
  {
    id: "2",
    name: "Sol",
    age: 3,
    location: 1500,
    breed: 1,
  },
};

Is there a way to access and push the data of this array of objects from outside of the getData() scoop

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I would suggest you declare an array outside the function scope and then add changes to it, or you can pass the update array as parameter.

let array = [
  {
    id: "1",
    name: "Slim",
    age: 5,
    location: 1500,
    breed: 500,
  },
  {
    id: "2",
    name: "Sol",
    age: 3,
    location: 1500,
    breed: 1,
  }];

//pass array as a parameter
async getData(array){
    return array
}

//update your array
array.push("your object");

//pass updated array in function call
getData(array);
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can also use this approach,

async function getData(item) {
  return [
  {
    id: "1",
    name: "Slim",
    age: 5,
    location: 1500,
    breed: 500,
  },
  {
    id: "2",
    name: "Sol",
    age: 3,
    location: 1500,
    breed: 1,
  },
  item
  ]
};

getData(  {
    id: "3",
    name: "obj",
    age: 5,
    location: 1500,
    breed: 1,
  });
about 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
Recomiéndame algunas ofertas
Necesito ayuda