Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!