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

237
Visualizações
removing (slice? splice?) item from array based on index

I have an array that looks like this,

[
    "slug.current == 'current'",
    "parent->slug.current == 'parentSlug'",
    "parent->parent->slug.current == 'parentParentSlug'",
    "parent->parent->parent->slug.current == 'parentParentParentSlug'"
]

This is created via this code,

path.split('/')
    .filter(i => i)
    .reverse()
    .map((slug, i) => {
      return `${'parent->'.repeat(i)}slug.current == '${slug}'`;
    });

I am wanting to remove the "parent->slug.current == 'parentSlug'" from ever being the error I would like to disregard after the split if possible,

I though it would need to something like,

path.split('/')
        .filter(i => i)
        .reverse()
        .splice(2, 2)
        .map((slug, i) => {
          return `${'parent->'.repeat(i)}slug.current == '${slug}'`;
        });

This returns the below,

[
    "slug.current == 'current'",
    "parent->slug.current == 'parentSlug'"
]

when what I want is,

[
        "slug.current == 'current'",
        "parent->slug.current == 'parentParentSlug'",
        "parent->parent->slug.current == 'parentParentParentSlug'"
    ]
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

change splice to this

.splice(1,1)

first argument is the index, second one means how many items after this index should be deleted (including the index it self)

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