1
a.getB.call().then(function (f) { console.log(f[1][0]) });

outputs:

BigNumber { s: 1, e: 20, c: [ 5000000 ] }

How can I access the value in c?

How can I save object f to a javascript variable?

Since I am saving an array of arrays, can I get the length of the Promise object?

2
  • 1
    f.toString() check BigNumber library also github.com/MikeMcl/bignumber.js
    – qbsp
    Commented Jun 5, 2018 at 7:40
  • Thanks for the help. I actually added another question which is kind of related.
    – Senju
    Commented Jun 5, 2018 at 7:42

1 Answer 1

3

How can I access the value in c?

the number is not only what is contained inside c but the whole BigNumber notation, which is accessible with a f.toString()

How can I save object f to a javascript variable?

f.toString() will give you a string, which can be saved into a variable. Same as you can keep it inside the BigNumber object and use the .toString to access to a readable value

Since I am saving an array of arrays, can I get the length of the Promise object?

this question doesn't make sense given the answers above, that kind of structure is the internal representation of the number stored into the BigNumber object

3
  • var b; a.getB.call().then(function (f) { b = f }); console.log('b: ' + b); outputs: b: undefined
    – Senju
    Commented Jun 5, 2018 at 8:01
  • 1
    that's because the function inside then is not executed yet. console.log will be printed before b will be assigned
    – qbsp
    Commented Jun 5, 2018 at 8:23
  • 1
    Seems correct. Fixed it with var b; await a.getB.call().then(function (f) { b = f }); console.log('b: ' + b); Thanks!
    – Senju
    Commented Jun 5, 2018 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.