Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[QUESTION] The order of things

1527088483
Darren
Pro
Sheet Author
API Scripter
When calling getAttrs( field1, field2, field3 ), will the returned array always be ordered field1, field2, field3 or is it possible the array will be ordered field2, field3, field1 or similar?  Every single test I've run comes out as the former (in order), but I'd like to be sure.  Reason is because I'm retrieving two fields that are supposed to be a name/value pair, and I was going to use Object.keys(v)[0] and Object.keys(v)[1] when referencing the returned data.  But if the returned array can be in any order, then my method won't work.
1527089842
Jakob
Sheet Author
API Scripter
When you say "array", do you mean "object"? Anyway, I wouldn't trust the order, and I don't see any reason you should do it this way... Object.keys(v)[0] and Object.keys(v)[1] is a lot less readable than just using the two names you've put in there in the first place.
1527130314

Edited 1527162174
Darren
Pro
Sheet Author
API Scripter
No.  I did mean "array" I was also wrong. It is an object. I had also written a rather lengthy reply explaining how I was having a devil of a time with the asynchronous nature of getAttrs() and setAttrs() and wound up using a separate function so that I wasn't using a local scope variable to reference the section id array, and that means I did end up using the names instead of Object.keys and more, but I accidentally deleted that text and I'm not about to type it in again, so instead you get this really long run-on sentence. I took the long road, but we got there.  It's working now.