Array.push is not a function

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

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

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.

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