JSFiddle - React, Tailwind, and code Playground

JavaScript

Array.prototype.hasObject = function(){
    for (i in this)
        if(typeof this[i] == "object")
            return true;

    return false;
}

Array.prototype.flatten  = function(){
    if (typeof condition == 'undefined') 
        condition = function(){return true;};

    narray = [];

    this.forEach(function(element){
        if (typeof element == 'object'){
            for(i in element){
                if (!element.hasOwnProperty(i))
                    continue;
                narray.push(element[i]);
            }
        } else 
            narray.push(element);
    });
    
    if (narray.hasObject())
        return narray.flatten();
    else return narray;
}
var array = [1,2,3,4,5, [1,3,2,4,1, [555,555,654, ['eu to malucooooo!']]]];
var newArray = array.flatten();

console.log(newArray)