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

140
Vistas
adding an object in an Array in javascript trough code?

My teacher made an array in my javascript file that i am not allowed to change. I am supposed to add new objects to it trough code without touching that array.

This is what my array looks like:

const words = [{
    dutch: "vork",
    english: "Fork",
    dutchDescription: "Iets waarmee je eet dat doorgaans vier tanden heeft.",
    englishDescription: "Something you eat with that usually has four tines.",
    isknown: false
  },
  {
    dutch: "mes",
    english: "knife",
    dutchDescription: "Bestek dat snijdt.",
    englishDescription: "Cutlery that cuts.",
    isknown: false
  },
  {
    dutch: "lepel",
    english: "spoon",
    dutchDescription: "Bestek waarmee je soep eet.",
    englishDescription: "Cutlery you use to eat soup.",
    isknown: false
  }
];

I tried to make it like this:

function addCustomWord(object) {
  const words2 = [{
    dutch: "testDutch",
    english: "testEnglish",
    dutchDescription: "dutchDiscriptionTest",
    englishDescription: "englishDiscriptionTest",
    isknown: false
  }]
  words.push(words2);
}

That clearly doesn't work and i am having a hard time trying to find anything that actualy works. I have been trying very different solutions for hours and i can't find anything that works. Could someone help me with my problem?

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

0

Remove the square brackets from words2 because words two is the element you need to add

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