3

I got a dict object structure like this:

var dict = {
    11: 0,
    12: 0,
    13: 0
    ...
};

I want to do this:

for (var i = 11; i < 42; i++) {
    dict.Add(i, 0);
}

But I do know "Add()" is not a function defined on the dict object.

So, how can I do it insead of manully write 11~42 line by line?

1
  • Exactly the same way you would index an array. Commented Dec 5, 2013 at 5:48

1 Answer 1

12

Is this what you are looking for?

for (var i = 11; i < 42; i++) {
    dict[i] = 0;
}

If you want to include 42 per your question, then change the < to a <=.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.