0

I am creating an app using React Native and Firebase. Sample data from firebase is as below.

Sample Data (Firebase)

accountName:"Frimi"
accountType:"debit"
createdAt:March 24, 2020 at 7:05:56 PM UTC+5:30
initialAmount:2000
userId:"t7DJ##################"
username:"de#####"

From this data's I need to get the total amount of the initialAmount from several data's. I do this in react native as follows

Fetch Total (React Native)

fetchTotalAmount = () => {
    const { accounts } = this.props
    const uid = firebase.auth().currentUser.uid
    return accounts && accounts.map((account) => {
        let total = 0
        return account.userId == uid ?
            total += account.initialAmount : null
    })
}

The problem here is instead of adding values I am getting concatenated string. I need to get sum of the initialAmount.

deluxan
  • 372
  • 1
  • 5
  • 22

1 Answers1

0

Try casting account.initialAmount to a Number like:

total += Number(account.initialAmount) : null

Look at this post for more casting references.

Dane B
  • 169
  • 12