0

So I have an array of javascript object named user with the following format. In an array called users.

{userId: 4, userName: "bob", password: "password", _id: "527abf6ebaa5eb8426000001", __v: 0}

But when i try and print the following objects values using the following lines of html/angular code

<tbody ng:repeat="user in users">
   <td ng:repeat="(key, value) in user">{{value}}</td>
</tbody>

I get the following ouput

0   528277c808cab8ac2b000001    password    5   Austin

At first I thought angular was printing the values out in reverse order but then I saw that the userId preceded the userName. So my question is why is angular printing out the values in the order that they are being printed out? My second question is is it possible using angular (key, value) in loop to print in the order of the object, so that userId is first and _v: is last?

Austin Davis
  • 2,756
  • 7
  • 23
  • 43
  • 4
    Objects do not have order! http://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order – epascarello Nov 12 '13 at 19:11
  • 4
    A Javascript object is a hash, without any ordering guarantee. If you need an order guarantee, use an array. – JB Nizet Nov 12 '13 at 19:13
  • 2
    If you absolutely need the order, don't run the second `ng-repeat` loop, manually enter your `td` values, they'll repeat for each array iteration. – tymeJV Nov 12 '13 at 19:14
  • 1
    These guys are correct. ECMAScript does not guarantee order on properties names. It looks like it's alphabetically ordered by Property name: __v, _id, password, userName, userId is alpha with symbols receiving precedence. – Kyle Mueller Nov 12 '13 at 19:20
  • I didn't notice the alaphbetic order I can use that... thanks – Austin Davis Nov 12 '13 at 19:32

0 Answers0