First off, I'm using Cheerio for some DOM access and parsing with Node.js.(首先,我使用Cheerio进行一些DOM访问,并使用Node.js进行解析。)
Good times.(美好的时光。)Heres the situation:(情况如下:)
I have a function that I need to create an object.(我具有创建对象所需的功能。)
That object uses variables for both its keys and values, and then return that single object.(该对象为其键和值使用变量,然后返回该单个对象。) Example:(例:)stuff = function (thing, callback) {
var inputs = $('div.quantity > input').map(function(){
var key = this.attr('name')
, value = this.attr('value');
return { key : value }
})
callback(null, inputs);
}
It outputs this:(它输出:)
[ { key: '1' }, { key: '1' } ]
( .map()
returns an array of objects fyi)(( .map()
返回对象数组fyi))
I need key
to actually be the string from this.attr('name')
.(我需要key
实际上是this.attr('name')
的字符串。)
Whats the best way to assign a string as a key in Javascript, considering what I'm trying to do?(考虑到我要做什么,在Java中将字符串分配为键的最佳方法是什么?)
ask by JDillon522 translate from so