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
messagekey, accessing it via element.message returnsundefined.ndoesn't exist whenmessageis defined. Consider usingconsole.log(`Hi ${element.name}`)?