SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: problem with associative Array
-
May 10, 2007, 00:06 #1
- Join Date
- Feb 2007
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
problem with associative Array
Hi,
I have an associative array like
x = {"Some Tag 0":{vals:[{sel:0, val:'SomeTagValue0'}, {sel:0, val:'SomeTagValue1'},{sel:1, val:'SomeTagValue2'}], edit:0},"Some Tag 1":{vals:[{sel:0, val:'SomeTagValue0'}, {sel:0, val:'SomeTagValue0'}], edit:1}};
y = {"Selected Tag 0":{vals:[{sel:0, val:'SomeTagValue0'}, {sel:0, val:'SomeTagValue0'},{sel:1, val:'SomeTagValue1'}], edit:0},"Selcted Tag 1":{vals:[{sel:0, val:'SomeTagValue0'}, {sel:0, val:'SomeTagValue1'}], edit:1}};
I just want to remove "Some Tag 1" from the array x and add it to y in the first position. Can somebody help me?
-
May 10, 2007, 00:21 #2
- Join Date
- Mar 2005
- Location
- USA
- Posts
- 5,482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
x and y aren't arrays. They're objects.
You can't add a new property to the beginning of an object in JS. You would need to make a new object in order put a new node (key/value pair) first.
Does the order really matter?We miss you, Dan Schulz.
Learn CSS. | X/HTML Validator | CSS validator
Dynamic Site Solutions
Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.
-
May 10, 2007, 00:24 #3
- Join Date
- Feb 2007
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi, I need to consider the order also. Can you please tell me how to create new object?
-
May 10, 2007, 02:15 #4
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
If order is important then put the information into a regular numbered array. Associative arrays and objects DO NOT support any form of ordering whatsoever.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
May 11, 2007, 01:44 #5
- Join Date
- Feb 2007
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thank you Stephen..But is there any way to append a child in first position?
-
May 11, 2007, 01:51 #6
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
insertBefore()
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
May 12, 2007, 01:20 #7
- Join Date
- Feb 2007
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi insertBefore is working fine..But cant we use nextsibling? its not working for me in firefox.
-
May 12, 2007, 15:04 #8
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
Are you sure that nextSibling is referencing the right node. Different browsers treat whitespace differently - whitespace counts as a node in some browsers and not others.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
Bookmarks