0

I'm using Node-Red and in node function I have:

  ...  
  res = dataTransform.transform();  
  //critic case: res = [{"pressure":null}];  
  key = Object.keys(res[0]);  
  if(res[0][[key]]!=null)  
  {  
   ...   
   console.log("res:   ", [key]+":"+res[0][[key]]);  
  }  

on console.log I have always:

res: 0:[object Object]

And it enters in if-statement always (also when the "res[0][[key]]" is null).

What was I mistake?

1 Answer 1

1

Object.keys returns an array containing the keys of the Object. Your code is using that entire array rather than a value from within it.

In order to get to the value of pressure, you would use:

var keys = Object.keys(res[0]);
var key = keys[0];
if (res[0][key] != null) {
    console.log(res[0][key]);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.