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

174
Views
JavaScript: curious to know if "if statements can substitute .include method

I am working on a .filter() method and a given solution has a .include() method in it. I was trying to solve the problem using an inner loop, next I switched to .filter and attempted using an if statement in the inner function.

Below is a code sample:



let arrayOne = [1,2,3,4,5,6];
let arrayTwo = [2,4,6,8,10,'water'];

const filterComparism=(arr1,arr2)=>{
  let newArray=[];
/**return arr1.filter(item=>arr2.includes(item)); this line of Code would solve the issue. is there an alternative step to solve below?
*/
for(let i = 0; i<arr1.length; i++){
  for(let j = 0; j< arr2.length; j++){


    
        newArray.push(arr1===arr2? return true);
  
        }
    }
  return newArray;
}

console.log(filterComparism(arrayOne,arrayTwo));
const filterComparism=(arr1,arr2)=>{ /**return arr1.filter(item=>arr2.includes(item)); this line of Code would solve the issue. is there an alternative step to solve below? */ return arr1.filter(item=>{ if(item===arr2){ return true; } return false; }); }

is there an alternative method to achieve this using an if statement in the inner function or using inner loops to compare values.

about 4 years ago · Juan Pablo Isaza
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!