Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda