0

in javascript and in solidity if you need to get gata from array index you can write like that let data = array[ index ] but in the testing phase, i saw javascript got data from array like this array ( index )

my array in solidity address[] public funders;

while testing in hardhat via JS

 it("add funders to array funders array", async () => {
        await fundMe.fund({ value: sendValue })
        let funder = await fundMe.funders(0)

        assert.equal(funder, deployer)
    })

as i know, in javascript and solidity, array works like that array [ index ] but how is this working. ????? it shows error if i use [ ] to get data from array.

image (6)

1 Answer 1

2

funders exactly is a function. Because you define funders in Solidity is public array, Solidity will auto generate a getter function for it with the same name like: function funders(uint index) public returns (address). You can read more in docs.

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.