最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Add element into javascript "dictionary" array - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question asked Dec 5, 2013 at 5:46 Edi WangEdi Wang 3,6376 gold badges36 silver badges51 bronze badges 1
  • Exactly the same way you would index an array. – user229044 Commented Dec 5, 2013 at 5:48
Add a ment  | 

1 Answer 1

Reset to default 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 <=.

发布评论

评论列表(0)

  1. 暂无评论