how to merge two arrays into a object using lodash

前端 未结 2 1974
没有蜡笔的小新
没有蜡笔的小新 2021-01-06 15:18

I am looking for best ways of doing this. I have two arrays:

key = [1,2,3];
value = [\'value1\', \'value2\', \'value3\']

The end result I

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-06 15:27

    Here's what you need

    _.zipObject(key, value);
    

    Actually ... no.

    Pure Javascript can though:

    var result = key.map(function(val, index){
      return { key: val, value: value[index] };
    });
    

提交回复
热议问题