Here are a few useful extra methods for the array class. Nothing fancy, just makes code look cleaner when you use then instead of manually writing the code.
PHP:
//=============================================================================
// Array_util
//=============================================================================
(function() {
//=============================================================================
Array.prototype.includes = function(value)
{
return (this.indexOf(value) >= 0);
};
Array.prototype.remove = function(value)
{
this.splice(this.indexOf(value), 1);
};
Array.prototype.tryRemove = function(value)
{
var index = this.indexOf(value);
if (index >= 0)
{
this.splice(index, 1);
return true;
}
return false;
};
//=============================================================================
})();Adding new methods to standard classes is a very bad practice
The includes method already exists in the array: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes