/    Sign up×
Community /Pin to ProfileBookmark

looping through {}

Hello,

i want to store some configuration in a variable like this:

[CODE]var Results = {
config : {
display: true,
bla: 1

},
configInitOnce: …[/CODE]

Now I want to loop through the Results.config properties and save them in a cookie like “display=true;bla=1;…” and also read them into the config var from the cookie.
How would I loop through the properties without specifying them?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 29.2008 — var str="";
for (var i in Results.config) {
str+=i+"="+Results.config[i]+";";
}
Copy linkTweet thisAlerts:
@CarelessJesusauthorSep 29.2008 — var str="";
for (var i in Results.config) {
str+=i+"="+Results.config[i]+";";
}
[/QUOTE]


Ok cool, thank you, I converted the object to a hash and used each. but this is simple.

now to get them back i use this:
[CODE]var configTmp = query.toQueryParams(";");
Results.config = Object.clone(configTmp);[/CODE]


any better way?
Copy linkTweet thisAlerts:
@KorSep 29.2008 — 
now to get them back i use this:
[CODE]var configTmp = query.toQueryParams(";");
Results.config = Object.clone(configTmp);[/CODE]

[/QUOTE]

Now this is [I]not[/I] javascript native code, it is probably a fragment of a framework using custom objects/methods. Until we will find out what lays behind [B]query[/B], [B]toQueryParams()[/B], [B]clone()[/B] we can not give you an answer.
Copy linkTweet thisAlerts:
@CarelessJesusauthorSep 29.2008 — Ah sorry forgot to mention that, its [I]prototype[/I]
×

Success!

Help @CarelessJesus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...