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

309
Visualizações
How to delete array from array?

There are excellent posts about deleting elements and arrays from arrays, but I can't find any that does it for this situation:

How can I remove the array containing UUID as its first element?

let arr = [
  ['Log entry ID', '_id'],
  ['UUID', '_source.uuid'],
  ['Timestamp', '_source.@timestamp'],
  ['Description', '_source._desc']
];
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can use Array.filter() and Array.includes() together as follows:

let arr = [
  ['Log entry ID', '_id'],
  ['UUID', '_source.uuid'],
  ['Timestamp', '_source.@timestamp'],
  ['Description', '_source._desc']
];

arr = arr.filter(subarr => !subarr.includes('UUID'));
// Or you can use subarr[0] !== 'UUID' if you want to check only first element

console.log(arr)

about 4 years ago · Juan Pablo Isaza Relatório

0

If you only want to remove elements whose first item is 'UUID', you can set the condition of the filter to whether the first item is not 'UUID':

let arr = [
  ['Log entry ID', '_id'],
  ['UUID', '_source.uuid'],
  ['Timestamp', '_source.@timestamp'],
  ['Description', '_source._desc']
];

const res = arr.filter(e => e[0]!='UUID')

console.log(res)

about 4 years ago · Juan Pablo Isaza Relatório

0

By default, you should be using const wherever possible, not let, so filter() is not an ideal solution.

Using const, you can still delete the desired array element effectively using the splice() method.

The splice() method follows the syntax splice(start, deleteCount, ...items) where start is the index to start the splice at, deleteCount is the number of elements you wish to remove starting at the start index, and items is any number of items you wish to inject at that same index once the deletion has completed.

Deletion is optional and can be subbed for 0 if you do not wish to delete any elements, but for this question, we will be removing 1 element, and we will exclude the items argument which is also optional, as we do not want to inject any additional elements.

For your task, we first need to find the index of the array element which has a first element equal to UUID. We can so using the findIndex() like this:

const index = arr.findIndex(e => e[0] === 'UUID');

Next, we can perform our splice() using that index value like this:

arr.splice(index, 1); // 1 for deleting a single array element

We an combine these two steps into one like this:

arr.splice(arr.findIndex(e => e[0] === 'UUID'), 1);

Here it is in action, including the array definition:

const arr = [
  ['Log entry ID', '_id'],
  ['UUID', '_source.uuid'],
  ['Timestamp', '_source.@timestamp'],
  ['Description', '_source._desc']
];

arr.splice(arr.findIndex(e => e[0] === 'UUID'), 1);

console.log(arr);

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