3 Replies Latest reply on Dec 6, 2006 7:10 AM by phil ashby

    Swapping element in an Array

    phil ashby Level 1
      Hi all,

      Can someone tell em what I'm doing wrong here? I basically want to swap the order of two elements in the array. The splice command works fine with only a single field in the array eg bob.push("aaa") but I get undefined when using multiple elements in the Array...help!?

      bob = new Array()
      bob.push({name:"aaa",age:1})
      bob.push({name:"bbb",age:2})
      bob.push({name:"ccc",age:3})
      bob.push({name:"ddd",age:4})
      bob.push({name:"eee",age:5})

      bob.splice(1,0,bob.splice(2,1))

      trace(bob[0].name) // gives aaa
      trace(bob[1].name) // gives undefined
      trace(bob[2].name) // gives bbb
      trace(bob[3].name) // gives ddd
      trace(bob[4].name) // gives eee