Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
hi,
JavaScript
for (i = 0; i < query.length; i++) {
   sessionStorage.setItem("list_data_key", JSON.stringify(query[i].id));
   alert(sessionStorage.getItem("list_data_key"));
}

In the above for loop i am putting the id value in the session storage,the problem i am facing is that,If the loop execute multiple times then in the sessionStorage the last value is only storing and loading my last record with that value only.

but i want for each iteration i want to retrieve the id value and with all the values I have to display all records.

how to do this?
Posted
Updated 10-Aug-12 1:48am
v2
Comments
Sergey Alexandrovich Kryukov 10-Aug-12 13:07pm    
Why without using a loop? Retrieve from where?.. or what to do you mean by "retrieve"?
--SA
Sergey Alexandrovich Kryukov 10-Aug-12 13:16pm    
If it JavaScript? If so, remove your "ASP.NET" tag as irrelevant.
--SA

1 solution

This it totally wrong thinking. Let's follow what happens:

You want to retrieve id values for all the values of some data container, JSON or not. Then you tried to do it in a loop and call alert inside the loop, by some weird reason. In other way, you write the loop in some wrong way, so the result cannot satisfy you. And what do you do next? You blame the loop! And ask: "how to do it without a loop?". Check up you logic!

Come on, it will lead your nowhere. When you had a compilation error, did you blame a compiler? Or the platform? why not? Some people are like that. But the question…

In your case, you should use your brain instead. You need to get all values, and then display the result. Collect all the results in the loop and store them in some container, an array; and, later, after the loop, use this array to display all records.

[EDIT]

And next time, when asking question, better don't tell what to use and what's not. It's rarely can be correct. Better focus on your problem itself, and don't forget to explain your ultimate goal. Not many would like to waste time on answering question based on misconception, so most experts would need to know your purpose.

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900