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

218
Visualizações
How to remove an object from an array if it has the letter a?

I need to make a function that receives 2 parameters, the first one is an array of a list of users that must contain first name, last name and phone numbers, at least 3 of those users must start with the letter "a", the second parameter is a callback. You must process the array and delete all the users whose name starts with the letter "a". Then send the new processed array to the callback. The callback must show in console, the list of all the names, concatenating first and last name.

const users =
    [{
        name: 'Diego',
        lastname: 'Garcia',
        phone: '12343'
    },
    {
        name: 'Camilo',
        lastname: 'Garcia',
        phone: '12343'
    }, {
        name: 'ana',
        lastname: 'Rodriguez',
        phone: '02343'
    }, {
        name: 'anastasia',
        lastname: 'Zapata',
        phone: '42343'
    }, {
        name: 'alejandra',
        lastname: 'Perez',
        phone: '52343'
    }];


const operation2 = (list) => {
    let x = [];
    let callback = {};

    callback = list.find(element => element.name.charAt(0) == 'a');
    let l = list.indexOf(callback)

    let g = list[l];
    console.log(g)

    if (callback) {

        x = list.splice(l, 1)
    } return list

}

console.log(operation2(users))

The code that I made does not work, it is not eliminating all the names that begin with "a", it only eliminates the first object of the array.

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

0

Array.find only finds the first match, you should probably filter out the elements you don't want:

const result = list.filter(element => element.name.charAt(0) !== 'a');
about 4 years ago · Juan Pablo Isaza Relatório

0

const users =
    [{
        name: 'Diego',
        lastname: 'Garcia',
        phone: '12343'
    },
    {
        name: 'Camilo',
        lastname: 'Garcia',
        phone: '12343'
    }, {
        name: 'ana',
        lastname: 'Rodriguez',
        phone: '02343'
    }, {
        name: 'anastasia',
        lastname: 'Zapata',
        phone: '42343'
    }, {
        name: 'alejandra',
        lastname: 'Perez',
        phone: '52343'
    }];



function func(list, callback) {
  let users = list.filter(u => !u.name.toLowerCase().startsWith('a'));
  callback(users)
}

func(users, (users) => {
  console.log(users)
})

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