Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda