TypeError: Cannot read property 'replace' of undefined

Hi,
I have a problem with my function node.
first of all, I have an array and I want to replace the points into commas and parse String into numbers. But it always says that the 'replace' is undefined. Why? can somebody help me pls

Here is the code:

for(i=0; i < measurements.length; i++){
dates[measurements[i]] = [parseFloat(msg.payload[measurements[i]].replace( /,/g, '.'))];
insertInto += dates[measurements[i]];
if(i < measurements.length-1){ insertInto += ','}

}
insertInto += ')';

if you place your code in </> it makes it easier to read.

Rather than trying to do everything in one line, start off by breaking your code down.
so do the replace on one line.
then the parsefloat it will make it easier to see where the issue is.

I'm on my phone but you say you have an array, but your code shows you have nested arrays. arrays in arrays.
You can also add "event" lines to your code so you can see what is happening. See https://nodered.org/docs/user-guide/writing-functions#logging-events

as your title says, its undefined.
I can pretty much gaurantee that at some point in your loop msg.payload[measurements[i]] will be undefined;

As @ukmoose said, break it down. e.g. create extra variables and debug them. e.g....

for(i=0; i < measurements.length; i++){
 let m = measurements[i];
 if(!m){
   node.warn(`measurements[${i}] is empty.  Accessing elements of msg.payload[ ] will fail `)
 }
 let item = msg.payload[m];
 if(typeof item != "string"){
   node.warn(`msg.payload[${m}] is not a string so calling .replace() will cause an error. `)
 }
 dates[m] = [parseFloat(item.replace( /,/g, '.'))]
 insertInto += dates[m];
 if(i < measurements.length-1){ 
   insertInto += ','
 }

}
 insertInto += ')';

I haven't finished the code or tested it but it should give you an idea on how to break it down and debug it.