Link to home
Start Free TrialLog in
Avatar of derrida
derrida

asked on

jquery looping issue

hi
i have this array returns from an ajax call. at the moment it is hard coded, it will be dynamic.
        $multilinevalues = array(
            array( 'x' => "2011 Q1" , 'y' => 3, 'z' => 6  ) ,
            array( 'x' => "2011 Q2" , 'y' => 10, 'z' => 1 ) ,
            array( 'x' => "2011 Q3" , 'y' => 2 , 'z' => 4) ,
            array( 'x' => "2011 Q4" , 'y' => 3 , 'z' => 3) ,
        );
       
        echo json_encode($multilinevalues);

Open in new window


i need to store the "x" key (not its value) in a variable. ( NOT 4 times, but just one).
i need to store the "y" and "z" keys (not the values) in an array ( again NOT 4 times, but only the one iteration). obviously in real data after y and z can be more.

how do i do that? tried many loops and get the keys but i need the x in a variable of its own and the y and z within an array, and just once not all the inner arrays.


best regards
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of derrida
derrida

ASKER

hey, first thanks for the help. but i needed not just the keys, i need the first key stored in a seperate veriable, and all the other keys in a separate array.
Can you post an example (Based on your sample input) of what you want out the other end
Avatar of derrida

ASKER

i need something like this:

loop this array and from it:
var firstKey = "x" (or whatever it will be once it will work dynamically.)notice, this one it the first key in the array but need to be transmitted as a string.
ver restKeys = ['y','z']; or whatever will be the reat of the keys array.
Avatar of derrida

ASKER

ok did it.
used this:
            var thefirst = thekeys[0].shift();
            var therest = thekeys[0];

thank you for the help. i was lost.
You are welcome, thanks for the points.