# Array.push is not a function

**URL:** <https://discourse.nodered.org/t/array-push-is-not-a-function/74826>\
**Category:** General\
**Created:** [7 February 2023 05:35 UTC](https://discourse.nodered.org/t/array-push-is-not-a-function/74826 "2023-02-07T05:35:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![atiki.nokin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/atiki.nokin/32/75382_2.png) [@atiki.nokin](https://discourse.nodered.org/u/atiki.nokin)\
**Post date:** [7 February 2023 05:35 UTC](https://discourse.nodered.org/t/array-push-is-not-a-function/74826/1 "2023-02-07T05:35:01Z")

</div>

Hello, I want to ask about some function here's my code

```auto
function inject(joint, step, array) {
    if (joint != 0 && step >= 0) {
        array.push(joint);
        global.set("dummyArray", array);
        msg.payload = {
            "Inject To Array" : joint,
            "Value In Array" : dummyArray
        }
    }
    else if (joint == 0 && step == 299) {
        let summary = array.reduce((x, y) => {
            return x + y;
        });
        var avg = summary / array.length;
        var min = array.min(...array);
        var max = array.max(...array);
    }
}

```

Can you tell me what's wrong with my function, when I run in debug shows error : **TypeError: array.push is not a function**

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [7 February 2023 07:37 UTC](https://discourse.nodered.org/t/array-push-is-not-a-function/74826/2 "2023-02-07T07:37:23Z")

</div>

> [@atiki.nokin](#):
>
> TypeError: array.push is not a function

The variable array is not an Array.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [7 February 2023 18:05 UTC](https://discourse.nodered.org/t/array-push-is-not-a-function/74826/3 "2023-02-07T18:05:18Z")

</div>

> [@Colin](#):
>
> The variable array is not an Array.

And you can use `Array.isArray(array)` to test that.

BTW, best not to use generic names like `array` in your code - it makes debugging really hard and can sometimes have unexpected results.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 April 2023 18:05 UTC](https://discourse.nodered.org/t/array-push-is-not-a-function/74826/4 "2023-04-08T18:05:32Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
