Vyse Clown
Vyse Clown

Reputation: 49

A function is not returning, but console.log is showing the content

I am making a function that will render the information of fees in each installment(key is equal to installment1, card[1][key] is the value, like a float 2.5), but my function is not returning! The console.log is working perfectly, anyone can give me an insight?!

export function returnInstallmentsWithFee(card, fee) {
   Object.keys(card[1]).forEach(function (key) {
      console.log('test', key, card[1][key])
      return (
        <div>
          {key}:{card[1][key]}
         </div>
      )
   })
}

Upvotes: 0

Views: 112

Answers (1)

Mechanic
Mechanic

Reputation: 5380

  1. your top level function (returnInstallmentsWithFee) doesn't have a return satatement;
  2. forEach doen't return anything, you may want to use .map()
export function returnInstallmentsWithFee(card, fee) {
      return Object.keys(card[1]).map(function (key) {
        console.log('test', key, card[1][key])
        return (
          <div>
            {key}:{card[1][key]}
          </div>
        )
      })
    }

Upvotes: 3

Related Questions