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

130
Visualizações
Array as argument and using the array in the new function in javascript
var filterKeys = ["hello this is javascript", "Movies"];
var title= "Hello"
searchKeyInNo = keySearch(filterKeys, title)

function KeySearch(filteredArray, searchKey) {
    var flag=0
    for (var i = 0; i<filteredArray.count; i++) {
        //array operations
        flag=1
    }
    return flag
}
var filterKeys = ["hello this is javascript", "Movies"];
var title= "Hello"
searchKeyInNo = keySearch(filterKeys, title)

function KeySearch(filteredArray, searchKey) {
    var tempArray = filteredArray
    var flag=0
    for (var i = 0; i<tempArray.count; i++) {
        //array operations
        flag=1
    }
    return flag
}

Can we use passed array as paramneter as a function array?
Can we pass and use the entire array as argument?
I even tried the second piece of code that I added a new array to copy the argument array to process the function scoped array.

UPDATE: VS Code never showed up suggestion for argumentarray.length. Thanks. WORKS NOW!

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

0

Try this. You were using .count instead of .length on the filtered array to get the count of elements.

function KeySearch(filteredArray, searchKey) 
{

    var flag=0
    for (var i = 0; i<filteredArray.length; i++)
    {
       if(filteredArray[i].toLowerCase()
           .includes(searchKey.toLowerCase()))
       {
          flag++
       }
    }
   return flag
};

console.log(KeySearch(["hello this is javascript", "Movies"], "Hello"))

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