score:1

Accepted answer

your this.simplestorageinstance.getbook is a promise, that means it is executed asynchronously.

to get it's result you either have to use .then or the new syntax async/await. with the following function your items array will be filled with the correct data :

you will have to put the async keyword before your parent function name if you choose this solution

for (i = 0; i < accountlength; i++) {
    items.push(await this.simplestorageinstance.getbook(searchaddress, i, { from: searchaddress }))
}

an even shorter syntax would imply using your raw array of accounts and map it instead of using its length :

const items = myaccounts.map(async () => await this.simplestorageinstance.getbook(searchaddress, i, { from: searchaddress }))

Related Query

More Query from same tag