Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda