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

137
Views
Trying to Change The Condition of without using null

I am trying to achieve a check for duplication and push items to array in the below code the functionality works well but instead of using a null is there any other way of doing it

array2.forEach((item) =>
   array1.includes(item)
 ? null
 : array1.push(item),
);
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can use && to short circuit the operation

const array1 = [1, 2, 3, 4, 5, 6],
  array2 = [4, 5, 6, 7, 8, 9, 10];
array2.forEach((item) => !array1.includes(item) && array1.push(item));
console.log(array1)

about 4 years ago · Juan Pablo Isaza Report

0

You can use a set

const set = new Set();
const brr = ["one","one"].forEach(item=> set.add(item));
Array.from(set) 
// --> ["one"]
about 4 years ago · Juan Pablo Isaza Report

0

You can use ES6 features like spread operator(...) and Set

let array1 = [1,2,3,4,5,6];
let array2 = [4,5,6,7,8,9,10];
const mergedArrays = [...array1, ...array2];
array1 = [...new Set(mergedArrays)];    // make the array elements unique
console.log(array1);

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