James111
James111

Reputation: 15903

How can I access a nested class object in Javascript?

I'm using the node scheduler & it creates an object like so:

{
  recurs: true,
  year: null,
  month: null,
  date: null,
  dayOfWeek: null,
  hour: null,
  minute: Range { start: 0, end: 59, step: 2 },
  second: 0 
}

How can I access the minute.Range.step value?

When I use minute.Range.step, node throws the following error:

TypeError: Cannot read property 'step' of undefined

I've also tried minutes.Range["step"] which is the same as what I tried above.

Upvotes: 0

Views: 80

Answers (1)

Freyja
Freyja

Reputation: 40814

When you're logging objects in Node, a class name immediately preceding an object tells you want class that object is.

So in your case, when Node logs

{
   ...
   minute: Range { start: 0, end: 59, step: 2 },
   ...
}

It actually means that the object you're printing is a plain object, which has a property minute (of type Range) with its own properties start, end and step.

So to refer to step, you have to use minute.step.

Upvotes: 1

Related Questions