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

111
Visualizações
buscar en una matriz por las dos primeras letras de cualquier palabra dentro de una matriz

usando la siguiente matriz, quiero buscar las primeras letras suponiendo que hay varias palabras en la misma matriz, debe buscar en cada palabra, si la encuentra debe regresar en una matriz

ejemplo

 const data= [ "the lions of teranga", "tiger woods", "The Truman Show", "Shutter Island", "The Gold Rush", ] ]

si coincide con "sh", debe buscar cada palabra y devolver

 ["Shutter Island", "The Truman Show"] but not The Gold Rush

si coincide con "leones", debe buscar cada palabra y devolver

 ["the lions of teranga"]
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Aquí está una de las soluciones con combinación de forEach y RegEx

 const data= [ "the lions of teranga", "tiger woods", "The Truman Show", "Shutter Island", "The Gold Rush", ] const filteredData = [] data.forEach(sentence => { let words = sentence.split(" ") words.forEach((word,index) => { if(word.match(/^lions?\w/gi)) { filteredData.push(sentence) } }) }) console.log(filteredData)

about 4 years ago · Juan Pablo Isaza Relatório

0

const data= [ "the lions of teranga", "tiger woods", "The Truman Show", "Shutter Island", "The Gold Rush", ] inputData = "lions" let a = data.filter(e => { str = e.toLowerCase() if (str.match(inputData.toLowerCase())){ return e } }) console.log(a)

Aquí el filtro devuelve los objetos que se devuelven verdaderos. Aquí puede buscar por cualquier palabra o carácter y regresar como una matriz.

about 4 years ago · Juan Pablo Isaza Relatório

0

//your data array const data= [ "the lions of teranga", "tiger woods", "The Truman Show", "Shutter Island", "The Gold Rush", ]; //your search letters,if it will be the same use const instead of var var search="sh"; //make your search case insensitive search=search.toLowerCase() //use for loop to go through every sentence for(var counter=0;counter<data.length;counter++) { //get the array of words var arrayOfWords=data[counter].match(/\b(\w+)\b/g); //use for loop to go through every word for(var counter2=0;counter2<arrayOfWords.length;counter2++) { //make word case insensitive var tempWord=arrayOfWords[counter2].toLowerCase(); //check if the search length does not exid your actuall word if(search.length<=tempWord.length) { //check if first letters match if(tempWord.slice(0,search.length==search) { //first letters match, you can put your logic here } else { //no match } } else { //search exids word } } }
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