SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    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?

  2. #2
    CSS & JS/DOM Adept bronze trophy
    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.

  3. #3
    SitePoint Enthusiast
    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?

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,824
    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="^$">

  5. #5
    SitePoint Enthusiast
    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?

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,824
    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="^$">

  7. #7
    SitePoint Enthusiast
    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.

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,824
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •