var options = {pageName: 'index', position: 1800} var obj = {} 现在要把这个属性添加到obj中变成 obj = { index:{position: options.position} } 前面的index根据上面的pageName动态变化如何处理?
var options = {pageName: 'index', position: 1800} var obj = {} obj = { [options.pageName]:{position: options.position} }
var result = {}; function objSet(keyName,targetName){ var obj = {}; for(var key in options){ if( key == keyName){ var temp = {}; temp[targetName] = options[targetName]; obj[keyName] = temp; break; } } return obj; } result = objSet("pageName","position"); //这样?