English 中文(简体)
采用动态钥匙:对物体的估价 [复制]
原标题:Passing in dynamic key:value pairs to an object literal? [duplicate]
  • 时间:2010-11-07 19:37:56
  •  标签:
  • javascript

我正在使用这一编号(见下文),试图在座标内填入字面上标明的物体<代码>Para amount。 我们需要<条码>关键:价值的配对,与编号<条码>i变量相配:<条码>{key_1:chunks ***,key_2:chunks/}。 然而,我的法典没有发挥作用。 <代码>钥匙_+i没有在字面上反映。

显然,我在这里缺少一些东西。 谁能告诉我什么? 感谢。

var Parameters=[];
var len = chunks.length;
for (var i = 0; i < len; i++) {
    var key= key_ +i
    obj= { key : chunks[i]};
   Parameters.push(obj)
}
最佳回答

EDIT: Use var obj ={}; obj[key] =chunks[i];

由于欧洲海洋研究学会文本将<代码>key in this {key:1}作为字面处理。

问题回答

也可用于寻找:肥料。 Do remmeber obj.key将寻找物体中的钥匙。

var obj = {
    test:1
}


var key =  test 
obj.test = obj[key] = 1

在此,骑士不会工作





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签