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

195
Views
JavaScript print values in array with function

I have the following code snippet in JS

names = [{name: "A"}, 
     {name: "B"}, 
         {name: "C"}, 
         {name: "D"}];

var returnNames = function(item, index) {
    var p = names[index].nome;
   return p;
}

names.forEach(returnNames);

I would like to print all the names according to the index but when I call the function it doesn't return any value What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Add the console.log within the function. Also, nome is misspelled.

var returnNames = function(item, index) {
    var p = names[index].name;
    console.log(p);
}
about 4 years ago · Juan Pablo Isaza Report

0

names = [{
    name: "A"
  },
  {
    name: "B"
  },
  {
    name: "C"
  },
  {
    name: "D"
  }
];

var arr = names.map(({name})=>name);
console.log(arr);

Must be the spelling mistake

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!