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

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

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 Denunciar

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 Denunciar

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 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