1

I am interacting with contentful and trying to interact with data using their api using Node.js.

I can show that a certain object has certain properties using Object.getOwnPropertyNames() but when I access them they are undefined. What am I doing wrong?

var currentValue = entry.fields;
    console.log("ELEMENT:" + element)
    console.log(Object.getOwnPropertyNames(entry.fields))
    console.log("PROP: " + entry.fields[element])

This displays for example:

 ELEMENT: averagePledgeBody
[ 'title',
  'subtitle',
  'description',
  'makingThePledgeFact1Heading',
  'makingThePledgeFact1Body',
  'makingThePledgeFact2Heading',
  'makingThePledgeFact2Body',
  'makingThePledgeFact3Heading',
  'makingThePledgeFact3Body',
  'averagePledgeTitle',
  'averagePledgeBody',
  'percentageMinimumPledge',
  'percentageAveragePledge',
  'pledgeAgreementTitle',
  'pledgeAgreementSubtitle',
  'pledgeAgreementButton',
  'callToAction' ]
PROP: undefined

Here you can see that the element I am looking for actually exists on the object, yet they all yield undefined when I actually do the lookup. Any ideas?

skaz
  • 21,962
  • 20
  • 69
  • 98

1 Answers1

0

In my case there was trailing whitespace on the string. Once I trimmed correctly, it worked as expected.

skaz
  • 21,962
  • 20
  • 69
  • 98