arrayclass

Run Settings
LanguageJavaScript
Language Version
Run Command
class myArray { constructor() { this.length = 0; this.data = {}; } get(index) { return this.data[index]; } push(item) { this.data[this.length] = item; this.length++; return this.length; } pop() { const lastItem = this.data[this.length - 1]; delete this.data[this.length - 1]; this.length--; return lastItem; } delete(index) { const lastItem = this.data[index]; this.shiftItems(index); return lastItem; } shiftItems(index) { for (let i = index; i < this.length - 1; i++) { this.data[i] = this.data[i + 1]; } delete this.data[this.length - 1]; this.length--; } } const newArray = new myArray(); newArray.get(0); newArray.push("eggs"); newArray.push("kell"); newArray.push("one"); console.log(newArray); newArray.push("apple"); newArray.push(1); console.log(newArray); newArray.pop() console.log(newArray); newArray.delete(2); console.log(newArray);
Editor Settings
Theme
Key bindings
Full width
Lines