Quick actions

cmd+k|ctrl+k

Navigation

Languages

Array

Snippet info

Language

JavaScript

Visibility

public

Author

cliffharvey06

Created

2025-11-06T00:37:35.793299Z

Updated

2025-11-14T21:22:47.583218Z

class MyArraay {
    constructor() {
        this.data = {};
        this.length = 0;
    }
    
    get(index) {
        if (this.length === 0) return [];
        return this.data[index];
    }
    
    push(item){
        this.data[this.length] = item;
        this.length++;
        return this.length;
    }
    
    pop(){
        let lastItem = this.data[this.length - 1];
        delete this.data[this.length - 1];
        
        this.length--;
        return lastItem;
    }
    
    delete(index) {
        let deletedItem = this.data[index];
        this.shiftItem(index);
        return deletedItem;
    }
    
    shiftItem(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 arr = new MyArray();
INFO