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

156
Visualizações
Javascript: includes return false while matching partial array element

Very simple example here:

var u = []
u.push("https://cloudinary.com/products/media_optimizer/web-performance-guide#get-started")

u.includes("https://cloudinary.com/products/media_optimizer/web-performance-guide") //return false

What am I doing wrong here?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Iterate over the array, checking each element.

const search = (arr, fragment) => arr.some(v => v.includes(fragment));

const u = [
  "https://cloudinary.com/products/media_optimizer/web-performance-guide#get-started"
];

const found = search(u, "https://cloudinary.com/products/media_optimizer/web-performance-guide");

console.log(found);

Reference:

  • .some()
about 4 years ago · Juan Pablo Isaza Relatório

0

The value you are searching for must be an exact match, and you are not searching for the ending #get-started

about 4 years ago · Juan Pablo Isaza Relatório

0

You are searching the array for an exact match to your string. You can use .includes(...) on the string in the array which will return true.

u[0].includes("https://cloudinary.com/products/media_optimizer/web-performance-guide")
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