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

116
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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