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

101
Visualizações
How to check if some object values contains some string in array of strings in JavaScript

I'm working on a simple translate option, but I'm stuck in case when I have duplicated titles. When titles are different it's working fine, but when I have duplicates it doesn't translate them.

Here is the function:

function Translate(language, availableLanguages) {
    let titles = [...document.getElementsByClassName('translate')]
    let titlesValues = []

    titles.forEach((title) => {
        titlesValues.push(title.textContent)
    })

    for (let i = 0; i < availableLanguages.length; i++) {
        const languageObject = availableLanguages[i];
        
        titlesValues.forEach((title) => {
            if(Object.values(languageObject).includes(title)) {
                titles[titlesValues.indexOf(title)].textContent = languageObject[language]
            }
        })
    }
}

Here is the incoming languages json:

{
    "Languages": [
        "English",
        "German"
    ]
}

Here is the availableLanguages json:

[
    {
        "Key": "Hello",
        "English": "Hello",
        "German": "Hallo"
    }
]
about 4 years ago · Santiago Gelvez
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