JSFiddle - React, Tailwind, and code Playground
JavaScript
// add a method conditionally
if (!('method' in Array.prototype)) {
Array.prototype.method = function (name, func) {
if (!this[name]) this[name] = func;
}
}
var arr = [1,2];
// exclusive push
arr.method('xadd', function (value) {
if (this.indexOf(value) === -1) {
this.push(value)
};
});
arr.xadd(3);
console.log(arr)