-
1. Re: JS CS5.5: Problem in Associative array (May be a bug)
John Hawkinson Jun 16, 2011 10:19 PM (in response to Green4ever)JavaScript Arrays are not associative arrays.
You want an Object!
(Also, for an Array, most prefer the notation myArray = [];).
So use var myArray = {};
(or you could say new Object() but I wouldn't).
You should probably also not name it myArray for the same reasons.
-
2. Re: JS CS5.5: Problem in Associative array (May be a bug)
Green4ever Jun 17, 2011 2:11 AM (in response to John Hawkinson)Hi John,
As you said, I have tried with this code. Still same result showing the ESTK's data browser.
var styles = [];//Tried with {} also styles["8 yes"] = "yes"; styles["85 No"] = "No";//Problem Here only styles["t85 yes"] = "yes"; styles["9 yes"] = "yes"; alert("Pause Here");Run the above code step by step and check "styles []" after executing each line in the data browser.
is this is a normal behaviour?
------------
Green4ever
-
3. Re: JS CS5.5: Problem in Associative array (May be a bug)
Harbs. Jun 17, 2011 3:32 AM (in response to Green4ever)Property names can not have spaces in them.
-
4. Re: JS CS5.5: Problem in Associative array (May be a bug)
Muppet Mark Jun 17, 2011 4:23 AM (in response to Harbs.)Nor would they be arrays…
var styles = {}; // Object styles.yes8 = 'yes'; styles.yes85 = 'No'; styles.t85 = 'yes'; styles.yes9 = ['yes','No','Yes']; alert(styles.yes85); alert(styles.yes9[0]); -
5. Re: JS CS5.5: Problem in Associative array (May be a bug)
John Hawkinson Jun 17, 2011 4:47 PM (in response to Green4ever)Sorry, I suppose I wasn't paying as close attention as I should have.
The reason to use an Object and not an Array is that Arrays are Objects with special features (like a .length property), and when you treat them like Objects, you get very confusing behavior when you access those special features. And if you don't ever use those special features, it all works, but then you there was no point to using the Array. For instance:
>> a = [ 1, 2, 3] 1,2,3 >> a[0] 1 >> a.length 3 >> a.pizza=4 4 >> a.length 3 >> a[4] undefined >> a['pizza'] 4
There is nothing wrong with spaces in property names. It certainly sounds like it confuses the ESTK's Data Browser, so I guess that's a bug, yeah.
-
6. Re: JS CS5.5: Problem in Associative array (May be a bug)
John Hawkinson Jun 17, 2011 4:49 PM (in response to Muppet Mark)Mark, what is your example intended to demonstrate?
-
7. Re: JS CS5.5: Problem in Associative array (May be a bug)
Green4ever Jun 17, 2011 9:05 PM (in response to John Hawkinson)Hi Harbs,
Property names can not have spaces in them.
I have tried this without space also. Same result came.
Hi John,
Thanks for paying close attention. :-)
It certainly sounds like it confuses the ESTK's Data Browser, so I guess that's a bug, yeah.
The value is not shown in the data browser, but if you alert it, it will show the correct result. Anyway my code works... ;-)
------
Green4ever
-
8. Re: JS CS5.5: Problem in Associative array (May be a bug)
Marc Autret Jun 20, 2011 12:25 AM (in response to Green4ever)Same bug in ESTK 3 / CS4.
The data browser definitely has a problem in displaying object properties whose name starts with a (recurring) digit. The issue is not related to property names that could contain a space character —which is not forbidden! Curiously, it seems that the bug only occurs with digits greater than 1.
Compare:
var obj = { "0a": null, "00b": null, "1a": null, "11b": null }; // The data browser properly displays all obj propertiesand:
var obj = { "2a": null, "22b": null, "5a": null, "55b": null }; // The data browser only displays obj['5a'] and obj['5b']!Note that this is not an internal ExtendScript bug. In all cases the object is properly set, the for...in loop works fine and obj.__count__ returns the correct number of enumerable properties.
Conclusion: ESTK sucks!
@+
Marc
-
9. Re: JS CS5.5: Problem in Associative array (May be a bug)
Harbs. Jun 20, 2011 4:20 AM (in response to Marc Autret)Sorry about that with the spaces.
Somehow I never realized you could do that (I guess I mixed up dot notation and bracket notation...)
It's very useful to know I was wrong! It looks like there's no limitation to what characters can be used as a key.
Thanks guys!
Harbs



