Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
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 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!