comparing and adding items to array of objects

前端 未结 4 2009
闹比i
闹比i 2021-01-25 04:13

The below code is supposed to:

1) go through the two arrays,

2) if an item exist in both arrays, add its value to the value of the similar item in the first arra

4条回答
  •  悲&欢浪女
    2021-01-25 04:40

    You can merge the arrays Or combine the array so it will automatically do what you want .

    var array3 = curInv.concat(newInv);

    If you want to find the unique elements

    // Merges both arrays and gets unique items var array3 = **

    arrayUnique(array1.concat(array2));
    
    function arrayUnique(array) {
       var a = array.concat(); 
       for(var i=0; i

    **

提交回复
热议问题