Merge keys array and values array into an object in Javascript
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have: var keys = [ "height" , "width" ]; var values = [ "12px" , "24px" ]; And I'd like to convert it into this object: { height : "12px" , width : "24px" } In Python, there's the simple idiom dict(zip(keys,values)) . Is there something similar in jQuery or plain Javascript, or do I have to do this the long way? 回答1: Simple JS function would be: function toObject ( names , values ) { var result = {}; for ( var i = 0 ; i Of course you could also actually implement functions like zip, etc as JS supports higher order types which