# Reduce() method Javascript is stupid! cannot use accumulator.push() \[SOLVED!\]

**URL:** <https://forum.freecodecamp.org/t/reduce-method-javascript-is-stupid-cannot-use-accumulator-push-solved/106827>\
**Category:** General\
**Created:** [April 17, 2017, 4:20pm UTC](https://forum.freecodecamp.org/t/reduce-method-javascript-is-stupid-cannot-use-accumulator-push-solved/106827 "2017-04-17T16:20:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fatherof10kids](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/fatherof10kids/32/541_2.png) [@Fatherof10kids](https://forum.freecodecamp.org/u/Fatherof10kids)\
**Post date:** [April 17, 2017, 4:20pm UTC](https://forum.freecodecamp.org/t/reduce-method-javascript-is-stupid-cannot-use-accumulator-push-solved/106827/1 "2017-04-17T16:20:45Z")

</div>

```auto

function uniteUnique(arr) {
            var newArr=[];
            for(index in arguments){
                //console.log(arguments[index]);
                // i got all args in arr, now i want to sorted the unique
                newArr= newArr.concat(arguments[index]); // concat arguments array save it to newArr
            }
            newArr.unshift([newArr[0]]); // create initial accumulator
            var completeNew= newArr.reduce(function(acc,curVal,curIndex){
                if(acc.indexOf(curVal)<0){
                    return acc.concat(curVal); // why i cant use acc.push() method here! but acc.concat works
                }
                else{
                    return acc;
                }
            });
            return completeNew;
        }
        uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);

```

In reduce method, why it only works when acc.concat(curVal) but not acc.push(). I also debugged it but cant find any mistake here!. Please help me, sorry for my english, also my messy code. Thanks

---

<div class="post-metadata">

**Author:** ![BenGitter](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bengitter/32/12192_2.png) [@BenGitter](https://forum.freecodecamp.org/u/BenGitter)\
**Post date:** [April 17, 2017, 4:34pm UTC](https://forum.freecodecamp.org/t/reduce-method-javascript-is-stupid-cannot-use-accumulator-push-solved/106827/2 "2017-04-17T16:34:29Z")

</div>

`.concat()` returns a new array, but `.push()` returns the length of the array.

> **[Array.prototype.concat()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)**
>
> The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.

  

> **[Array.prototype.push()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)**
>
> The push() method adds one or more elements to the end of an array and returns the new length of the array.

---

<div class="post-metadata">

**Author:** ![Fatherof10kids](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/fatherof10kids/32/541_2.png) [@Fatherof10kids](https://forum.freecodecamp.org/u/Fatherof10kids)\
**Post date:** [April 17, 2017, 4:42pm UTC](https://forum.freecodecamp.org/t/reduce-method-javascript-is-stupid-cannot-use-accumulator-push-solved/106827/4 "2017-04-17T16:42:56Z")

</div>

oh now im stupid. Thanks alot for fast reply, and your time. You are really a hero here! thank you! 🎉

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 5:58pm UTC](https://forum.freecodecamp.org/t/reduce-method-javascript-is-stupid-cannot-use-accumulator-push-solved/106827/5 "2021-01-16T17:58:25Z")

</div>

Closed on January 16, 2021, 5:58pm UTC


