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

122
Visualizações
function to Get array and specific start letter and end letter and then return a list of names that starts and end with them

I have a long array of objects. I want to write a function to find for example names that start with specific letter and end with another specific letter and return a list of names that starts and end with them.

I tried some solutions but did not get answer.

Here I use a simple list: and I want a list that name start with "A" and end with "i" or any other case

myList = [{name: "Aji",family: "Ziansi"}, { name: "Alex", family: "ortega"}, {name:"Amandi",family: "Sedirini"}];

Output should be like this:

desiredLiset = [{name: "Aji",family: "Ziansi"}, {name:"Amandi",family: "Sedirini"}];

just in function declaration method.

Any solutions would be appreciated.

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

We can use Array.filter()

const myList = [{
  name: "Aji",
  family: "Ziansi"
}, {
  name: "Alex",
  family: "ortega"
}, {
  name: "Amandi",
  family: "Sedirini"
}];

const filterList = (list, start, end) => {
  return list.filter(obj => {
    const name = obj.name;
    return name[0] === start && name[name.length - 1] === end;
  });
};

const filtered = filterList(myList, "A", "i");
console.log(filtered);

about 4 years ago · Santiago Trujillo Relatório

0

You can use .filter() to get a list of the names you want:

myList = [{name: "Aji",family: "Ziansi"}, { name: "Alex", family: "ortega"}, {name:"Amandi",family: "Sedirini"}];

let desiredLiset = myList.filter(function(n){
    return n.name.match(/^A.*i$/i) // Names that begin with 'A' and end with 'i'
});

console.log(desiredLiset)
// 0: Object { name: "Aji", family: "Ziansi" }
// ​1: Object { name: "Amandi", family: "Sedirini" }
about 4 years ago · Santiago Trujillo Relatório

0

Try this:

myList = [{name: "Aji",family: "Ziansi"}, { name: "Alex", family: "ortega"}, {name:"Amandi",family: "Sedirini"}];

const start='A'
const end='i'
const startEndRE = new RegExp(`^${start}.*${end}$`)
myList.filter(item=>(
    startEndRE.test(item.name)
))

// Result 
// [
//   { name: 'Aji', family: 'Ziansi' },
//   { name: 'Amandi', family: 'Sedirini' }
// ]
about 4 years ago · Santiago Trujillo 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