Merging objects (associative arrays)

前端 未结 16 1220
野的像风
野的像风 2020-12-04 08:20

What’s the best/standard way of merging two associative arrays in JavaScript? Does everyone just do it by rolling their own for loop?

16条回答
  •  攒了一身酷
    2020-12-04 08:56

    Keep it simple...

    function mergeArray(array1,array2) {
      for(item in array1) {
        array2[item] = array1[item];
      }
      return array2;
    }
    

提交回复
热议问题