title: Create array from map in Protractor
body: <p>I have this <strong>HTML</strong></p>
  
  <pre><code>&lt;tr ng-repeat="row in entityL"&gt;
    &lt;td&gt;{{row.Name}}&lt;/td&gt;
    &lt;td&gt;{{row.Surname}}&lt;/td&gt;
    &lt;td&gt;{{row.Initials}}&lt;/td&gt;
    &lt;td&gt;{{row.RolDivisionList.Name}}&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>And I want to get an array with all those values in Protractor, and I must access to the first one.</p>
  
  <p>I tried with this <strong>Protractor function in a page object</strong></p>
  
  <pre><code>this.getAllUsers = function() {
    var userList = element.all(by.repeater('row in entityL'));
  
    return userList.map(function(tr) {    
      return {
        name: tr.element(by.binding('row.Name')).getText(),
        surname: tr.element(by.binding('row.Surname')).getText(),
        initials: tr.element(by.binding('row.Initials')).getText(),
        rolDivision: tr.element(by.binding('row.RolDivisionList.Name')).getText()
      };
    });
  };
  </code></pre>
  
  <p>I get a <strong>result</strong> like this</p>
  
  <pre><code>[ 
     { name : 'Name1', surname : 'Surname1', initials : 'Initials1', rolDivision : 'Rol1' }, 
     { name : 'Name2', surname : 'Surname2', initials : 'Initials2', rolDivision : 'Rol2' } 
  ]
  </code></pre>
  
  <p>But I can't access to it's values, I tried <code>array[0]</code>, <code>array[0]['name']</code>, <code>array[0].name</code>, <code>array.get(0)</code>... and nothing works. I also tried to wrap the <code>return</code> inside the <code>map</code> with <code>[]</code> but didn't worked either.</p>
  
  <p>The fact is that <strong>I just want the first user</strong>, but I just can't achieve it and must return all of them, so if you know how to return just the first to the test that would be great too. </p>
  
  <p>This is the <strong>test code</strong> (just the <code>it</code>):</p>
  
  <pre><code>iit('should return the first user', function() {    
    expect(userListPage.getAllUsers()[0]['name']).toBe('Name1');
  });
  </code></pre>
  
  <h1>New experiments</h1>
  
  <p>I tried some experiments with the previous code, trying to learn about how Protractor works and this is what I got.</p>
  
  <p>I will use the previous HTML and the new <strong>Protractor functions in a page object</strong></p>
  
  <pre><code>var UserListPage = function() {
    this.userList = element.all(by.repeater('row in entityL'));
  
    this.getFirstUser = function() {
      return {
        name: element(by.binding('row.Name')).getText(),
        surname: element(by.binding('row.Surname')).getText(),
        initials: element(by.binding('row.Initials')).getText(),
        rolDivision: element(by.binding('row.RolDivisionList.Name')).getText()
      };
    };
  
    this.getUserData = function (tr) {
      return {
        name: tr.element(by.binding('row.Name')).getText(),
        surname: tr.element(by.binding('row.Surname')).getText(),
        initials: tr.element(by.binding('row.Initials')).getText(),
        rolDivision: tr.element(by.binding('row.RolDivisionList.Name')).getText()
      };
    };
  
    this.getAllUsers = function() {    
      return this.userList.map(function(tr) {      
        return {
          name: tr.element(by.binding('row.Name')).getText(),
          surname: tr.element(by.binding('row.Surname')).getText(),
          initials: tr.element(by.binding('row.Initials')).getText(),
          rolDivision: tr.element(by.binding('row.RolDivisionList.Name')).getText()
        };
      });
    };
  };
  
  module.exports = UserListPage;
  </code></pre>
  
  <p>And now the test block with all the experiments</p>
  
  <pre><code>it('should test things', function() {
    userListPage.getAllUsers().then(function(array) {
      //First user array
      expect(array[0]).toEqual("");
      //Name of the first user
      expect(array[0].name).toEqual("");
    });
  
    //Array with all users
    expect(userListPage.getAllUsers()).toEqual("");
  
    //Name of the first user
    expect(userListPage.getAllUsers().name).toEqual("");
  
    //undefined
    expect(userListPage.getAllUsers()[0]).toEqual("");
  
    //Cannot read property 'name' of undefined
    expect(userListPage.getAllUsers()[0].name).toEqual("");
  
  
  
    //.then is not a function
    userListPage.getFirstUser().then(function(array) {});
  
    //ERROR Process out of memory
    expect(userListPage.getFirstUser()).toEqual("");
  
    //Name of the first user
    expect(userListPage.getFirstUser().name).toEqual("");
  
    //undefined
    expect(userListPage.getFirstUser()[0]).toEqual("");
  
    //Cannot read property 'name' of undefined
    expect(userListPage.getFirstUser()[0].name).toEqual("");
  
  
  
    //.then is not a function
    userListPage.getUserData(userListPage.userList.first()).then(function(array){});
  
    //ERROR Process out of memory
    expect(userListPage.getUserData(userListPage.userList.first())).toEqual("");
  
    //Name of the first user
    expect(userListPage.getUserData(userListPage.userList.first()).name).toEqual("");
  
    //undefined
    expect(userListPage.getUserData(userListPage.userList.first())[0]).toEqual("");
  
    //Cannot read property 'name' of undefined
    expect(userListPage.getUserData(userListPage.userList.first())[0].name).toEqual("");
  
  });
  </code></pre>
  
  <p>It seems strange to me that this <code>expect(userListPage.getFirstUser()).toEqual("");</code> stop Protractor with an error and this <code>expect(userListPage.getFirstUser().name).toEqual("");</code> return the correct value.</p>
  
  <p>Can someone also explain why this things happens?</p>
  
  <p><strong>PD: Should I put all this in a new question?</strong></p>