0

A function which is returning data in objects format. I want to get the single value from this object but it is returning undefined. This is my code.

var todayEvents = plugin.getDateEvents(day);
var str = JSON.stringify(todayEvents);
console.log(str);

This is how it is displaying in console.

[
  {
    "startDate": "2020-07-14T14:29:53.525Z",
    "endDate": 1594823393525,
    "summary": "Visit of the Louvre",
    "status": "pending"
  }
]

I want to get value of status from this object. I tried like this but it is returning undefined value.

str.status
str[0].status

Any suggestion regarding this will be helpful.

wplearner
  • 405
  • 6
  • 19

2 Answers2

0

You need to get by 0th index.so you get like this str[0] object

to access the name property you do the following way.

str[0].status

let str = [
  {
    "startDate": "2020-07-14T14:29:53.525Z",
    "endDate": 1594823393525,
    "summary": "Visit of the Louvre",
    "status": "pending"
  }
];

//then you can access like this
console.log(str[0].status);
Vijay Palaskar
  • 526
  • 5
  • 15
0

access the object in the variable first and then the properties

object=[
  {
    "startDate": "2020-07-14T14:29:53.525Z",
    "endDate": 1594823393525,
    "summary": "Visit of the Louvre",
    "status": "pending"
  }
]

console.log(object[0].status)
Sven.hig
  • 4,449
  • 2
  • 8
  • 18