0

From what I can tell when I dynamically make a new column without using a push it is done backwards in IE. Doing a sheet[r].push() would not work so I dont know how else to do this.

Going to illustrate this in a code flow.

 //{" ":"545"} current object.
 sheet[r][colN[elmt][ceeLineData.ColLabel].toString()] = dat[count + c].data;
 //{" ":"545","20":"1"} current object.

So the line did nothing more then simply add a new column titled "20" with rowdata of "1" Something like this:

[" "]--["20"]//columns 0,1
["545"]["1"]//row 0

this is true for ff,safari,opera,chrome now for IE it did this

["20"]--[" "]
["1"]["545"]

why?

Here are the brake down values of the above for reference.

alert( r ) //0
alert( JSON.stringify( sheet[r] ) ); // {" ":"545"}
alert( c ) //1
alert( count + c ) //56
alert( dat[count + c].data ) //1
alert( elmt ) // 9 
alert( ceeLineData.ColLabel ) //BP In Hg
alert( colN[elmt][ceeLineData.ColLabel].toString() )//20
alert( JSON.stringify( sheet[r] ) ); // {" ":"545","20":"1"}//not IE
alert( JSON.stringify( sheet[r] ) ); // {"20":"1"," ":"545"}//IE
2
  • 2
    Or to sum up your question in one sentence: "Why does JSON.stringify() in IE list object properties in a different order to JSON.stringify() in other browsers?" Commented May 20, 2013 at 13:25
  • Ok good observation. but the resulting data when displayed ( UI table ) is also backwards. I dont know if you can see this but here is an image of it infragistics.com/community/cfs-filesystemfile.ashx/__key/… Commented May 20, 2013 at 13:43

1 Answer 1

1

When you use property names like " " (a space), you're not appending elements to the array. You're just adding a named property to the object. Named properties and the numerically-indexed array properties have no defined ordering. In fact it looks like you don't really even have arrays anyway; those are just simple objects as is clear from the fact that they're logged with curly braces.

JavaScript Array instances are also objects, of course, but they have special behaviors. There's no defined ordering of the properties of plain objects, so you can't expect them to be presented by the system (when logging objects, or in for ... in loops, etc) to be in any particular order.

Sign up to request clarification or add additional context in comments.

4 Comments

would there be a way to order it once its built?
If you need key/value pairs in a specific order you can put them as separate objects into an array, like this: [{" ":"545"}, {"20":"1"}], or use two arrays [" ", "20"] and ["545", "1"], or have your original object {" ":"545","20":"1"} with an associated array that gives the keys in the desired order [" ", "20"].
I see your point. In this case it wont work as the data I'm building is for a JS UI table that expects objects. I may look in to sorting the table.
@user2144480 yes sorting the table would work. There's really no way to force an ordering of object properties; it's all managed by the runtime and the spec doesn't require it to worry about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.