Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
Javascript array out of bounds functions

in javascript when an index is out of the bounds of the array, it gets extended with undefineds.

Are there any function calls happening behind the scenes?

For example:

var w = []
for (i = 0; i < 10; i++) {
    w[(i << 4) + 15] = i
}

I am trying some prototype poisoning exercises and I noticed an array used with indexes outside its bounds, so I am hoping to modify functions related to this if it is possible.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can override Array.prototype like this:

NOTE the limits in the for loop!

for (let i = -1000; i < 1000; i++) {
    Object.defineProperty(Array.prototype, i, {
        get() {
            if (this[`_${i}`] === undefined) return 'No value'; // or throw new Error('No value');
            return this[`_${i}`];
        },
        set(v) {
            return this[`_${i}`] = v;
        },
    });
}

const arr = [];

console.log(arr[1]); // No value
arr[1] = 'I have a value'; // set value
console.log(arr[1]); // get the value 'I have a value'
console.log(arr[-1]); // No value
console.log(arr[-100]); // No value
console.log(arr[0]); // No value
console.log(arr[100]); // No value
console.log(arr[10000]); // undefined (because of the limits are -1000 to 1000)

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use Proxy:

const arr = new Proxy([], {
    get(target, property) {
        return target[property];
    },
    set(target, property, value) {
        // do your work here ... for example: print some values:
        console.log('oldValue=', target[property]);
        console.log('newValue=', value);
        console.log('index=', property);

        // set the new value - default behaviour
        target[property] = value;

        // Return true if successful. In strict mode, returning false will throw a TypeError exception.
        return true;
    },
});

arr[3] = 'https://sidanmor.com/';

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda