Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!