0

I have a function which gets data from my mongodb database. I am trying to console log the result. I can see the result as

console.log(result);

This gives

[
  {
    _id: 5f2940b77e6f8b26e0726cb9,
    Val_String: '2',
    T1_String: '2162',
    T2_String: '2068',
    T3_String: '1950',
    T4_String: '1956',
    Pdiff_String: '-0.010000',
    Time_String: '2020-05-20 12:51:20 GMT',
    __v: 0
  }
]

However, when I do:

var T1 = result.T1_String;
console.log(T1);

I get undefined. So my question is how do I correctly parse this to get my data.

1
  • write result[0].T1_string Commented Aug 5, 2020 at 8:54

2 Answers 2

1

you have to access the first object in the list. Therefore

var T1 = result[0].T1_String;
console.log(T1);

will give the t1 string

Sign up to request clarification or add additional context in comments.

Comments

1

The result gives back an array of objects and not just a single object. Access the objects by square bracket notation []

var T1 = result[0].T1_String; //result[0] is the first object in the array

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.