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

73
Visualizações
Finding enumerable properties more directly

I have the following which iterates through an object/array to print its enumerable properties:

const reg = /(?<num>hi)(there)/g;
const str = 'hithere';
let matches = Array.from(str.matchAll(reg)); // same thing as [...matches[;]]
for (let match of matches) {
    for (let elem of match) {
        console.log('**', elem);
    }
}

The actual object looks like this:

  [
    'hithere'.   // enumerable
    'hi',        // enumerable
    'there',     // enumerable
    index: 0,                                      // no
    input: 'hithere',                              // no
    groups: [Object: null prototype] { num: 'hi' } // no
  ], ...

Is there a more direct way to (1) get the enumerable properties in an object; or (2) test to see if an Object property is enumerable? I thought the following would work but it seems to always print true for me:

matches[0].propertyIsEnumerable('index'));
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

That's a very good question.

for ... of does not necessarily loop over all enumerable properties in an object the way that for ... in does. Javascript objects can define their own iterable protocol.

The booleans your getting from propertyIsEnumerable are correct.

So to answer your questions directly: (1) yes: a for... in loop (2) no: your test is working fine

const reg = /(?<num>hi)(there)/g;
const str = 'hithere';
let matches = Array.from(str.matchAll(reg)); // same thing as [...matches[;]]
for (let match in matches) {
    for (let elem in matches[match]) {
        console.log(elem, matches[match][elem]);
    }
}

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