Creating a JavaScript Object from two arrays

后端 未结 9 877
北海茫月
北海茫月 2020-11-28 06:17

I have two arrays: newParamArr[i] and paramVal[i].

Example values in the newParamArr[i] array: [\"Name\", \"Age\", \"Ema

9条回答
  •  借酒劲吻你
    2020-11-28 06:56

    This one works for me.

        var keys = ['foo', 'bar', 'baz'];
        var values = [11, 22, 33]
        var result = {};
        keys.forEach(function(key, i){result[key] = values[i]});
        console.log(result);

提交回复
热议问题