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

114
Views
how to use the object variable inside string

I'm trying to create a string with a prefix variable which will dynamically allocate from the array of object but it shows UNDEFINED

this is my code

    app.post("/objectlooping",(req,res)=>{
    const myArray = [{"name":"venkat","number":"2345678900"}, {"name":"jhon","number":"2345678900"}, {"name":"selva","number":"2345678900"}];
    const message =`HI ${n}`;
myArray.forEach((element, index, array) => {
    var n=element.name;
    console.log(element.message); 
    
});
     
   });

can anyone help me to achieve this but this shows undefined

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

0

If I understand this correctly you're trying to log a message for each name.

You can map over the objects in the array and return an array containing a message for each name in each object, and then join that array of messages up with a line break.

const myArray=[{name:"venkat",number:"2345678900"},{name:"jhon",number:"2345678900"},{name:"selva",number:"2345678900"}];

const message = myArray.map(obj => {
  return `Hi ${obj.name}`;
}).join('\n');

console.log(message);

about 4 years ago · Juan Pablo Isaza Report

0

use message fn instead of variable then call it like

const message = (name)=>`Hi ${name}`
myArray.forEach((element, index, array) => {
    var name=element.name;
    console.log(message(name)); 
    
});
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!