Javascript Replace Element In Array Python Memory Allocation Strategies