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

357
Visualizações
How to find index nested object within array in JavaScript

I have an JS array with nested objects as a "task list". They each are added with different Urgency properties. Now my function needs to find the highest urgency value - set this to a variable and then remove it from the array.

I am stuck at removing it from the original array. The trouble I have might just be finding the index:

function newTask() {

  // reducing the "task list" to just the highest urgency
  let maxObj = taskList.reduce((max, obj) => (max.stockUrgency > obj.stockUrgency) ? max : obj);
  
  outputNewtask = JSON.stringify(maxObj, null, 4); 
 
 let index = taskList.indexOf("outputNewtask")
 
 console.log(index)

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If your reduce works fine, then you can use that object to find the index and remove it from the list using splice:

    let maxObj = taskList.reduce((max, obj) => (max.stockUrgency > obj.stockUrgency) ? max : obj);

    taskList.splice(taskList.indexOf(maxObj), 1);

    outputNewtask = JSON.stringify(maxObj, null, 4); 
about 4 years ago · Juan Pablo Isaza Relatório

0

This code should solve your problem

const highestUrgencyValue = Math.max(...taskList.map(t => t.stockUrgency));
const highestUrgencyIndex = taskList.findIndex(task => task.stockUrgency === highestUrgencyValue);
taskList.splice(highestUrgencyIndex, 1);
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