Since struct cannot be output from solidity to web3js, I'm using arrays, I could get single datatype array in the below code(userAddress), but I'm not able to take multiple value in array(userName,userTarget).Any suggestions howto would be great


struct Person
        address userAddress;
        string userName;
        uint userTarget;
     mapping (uint => person) Persons;
     uint[] public personAccounts;
     uint incr = 0;

     function setDetailse(string  data, uint target) public
        uint icr = incr++;
        address _address = msg.sender;
        var person = persons[icr];

        person .userAddress = _address;
        person .userName= _vote;
        person .userTarget = target;
        person Accounts.push(icr) -1;

   function getPerson() view public returns(uint[])
       uint256[] memory data =  new uint256[](11);
       for(uint i = 1; i<=10 ;i++)
       return data;


GetDetails: function(Data, account) {
  var dataInstance;

  web3.eth.getAccounts(function(error, accounts) {
    if (error) {

    var account = accounts[0];

    App.contracts.Details.deployed().then(function(instance) {
      dataInstance= instance;
      return dataInstance.getPerson();
    }).thenfunction((numbers => {
      const [ nums ] = numbers;
      for (var i = 0; i <nums.length; i++) 
          console.log("address: "+nums[i]);
  })).catch(function(err) {
      console.log("error executed");
  • 2
    you can make other more variable for userAddress,userName,userTarget like you did for data as - uint256[] memory data = new uint256[](11); and return all thee values of variables in array once .
    – Gopal ojha
    Jul 3, 2018 at 9:20

1 Answer 1


One can not create an array of multiple data types. An array must contain elements of the same data type. As one can not return a struct from solidity function you cannot use an array of struct. Refer this question for how to return multiple data types from a solidity function.

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.