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

122
Views
i have Two array i want that unique value of array
let array1 = ["apple", "banana", "mango"];
let array2 = ["apple", "banana", "mango", "red", "green"];

I want output is = array3 = [ "red", "green"];

I want to concat array1 and array2 and remove the duplicate code and output is array3.

There are two common ways (in ES5 and ES6, respectively) of getting unique values in JavaScript arrays of primitive values. Basically, in ES5, you first define a distinct callback to check if a value first occurs in the original array, then filter the original array so that only first-occurred elements are kept.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can easily filter out the common elements using Map as:

let array1 = ["apple", "banana", "mango"];
let array2 = ["apple", "banana", "mango", "red", "green"];

const map = [...array1, ...array2].reduce(
  (map, curr) => map.set(curr, (map.get(curr) ?? 0) + 1),
  new Map()
);

const result = [];
for (let [k, v] of map) {
  if (v === 1) result.push(k);
}
console.log(result);

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!