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.
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
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);
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you post an example (Based on your sample input) of what you want out the other end
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.
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.
ASKER
ok did it.
used this:
var thefirst = thekeys[0].shift();
var therest = thekeys[0];
thank you for the help. i was lost.
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.
ASKER