Skip to main content
Active reading - but more work is needed, e.g. near "want without duplicate".
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132

Best Solution.The best solution...

youYou can check directly in the browser Consoleconsole by hitting...

Without Duplicate###Without duplicate

a = [1, 2, 3];
b = [3, 2, 1, "prince"];

a.concat(b.filter(function(el) {
        return a.indexOf(el) === -1;
    }));

With Duplicate###With duplicate

["prince", "asish", 5].concat(["ravi", 4])

ifIf you Want Without Duplicatewant without duplicate you can try a better Sol.solution from here - Shouting Code.

[1, 2, 3].concat([3, 2, 1, "prince"].filter(function(el) {
        return [1, 2, 3].indexOf(el) === -1;
    }));

Try Onon Chrome Browser Consolebrowser console

 f12 > console 

OutPutOutput:

["prince", "asish", 5, "ravi", 4]

[1, 2, 3, "prince"]

Best Solution....

you can check directly in browser Console by hitting...

Without Duplicate

a = [1,2,3];
b = [3,2,1,"prince"];

a.concat(b.filter(function(el) {
        return a.indexOf(el) === -1;
    }));

With Duplicate

["prince","asish",5].concat(["ravi",4])

if you Want Without Duplicate you can try better Sol. from here - Shouting Code

[1,2,3].concat([3,2,1,"prince"].filter(function(el) {
        return [1,2,3].indexOf(el) === -1;
    }));

Try On Chrome Browser Console

 f12 > console 

OutPut:

["prince", "asish", 5, "ravi", 4]

[1, 2, 3, "prince"]

The best solution...

You can check directly in the browser console by hitting...

###Without duplicate

a = [1, 2, 3];
b = [3, 2, 1, "prince"];

a.concat(b.filter(function(el) {
    return a.indexOf(el) === -1;
}));

###With duplicate

["prince", "asish", 5].concat(["ravi", 4])

If you want without duplicate you can try a better solution from here - Shouting Code.

[1, 2, 3].concat([3, 2, 1, "prince"].filter(function(el) {
    return [1, 2, 3].indexOf(el) === -1;
}));

Try on Chrome browser console

 f12 > console

Output:

["prince", "asish", 5, "ravi", 4]

[1, 2, 3, "prince"]
correction........
Source Link
Zigri2612
  • 2.3k
  • 21
  • 33

Its Working fine aBest Solution.concat(b); With Duplicate...

you can check directly in browser Console by hitting...

Without Duplicate

a = [1,2,3];
b = [3,2,1,"prince"];

a.concat(b.filter(function(el) {
        return a.indexOf(el) === -1;
    }));

With Duplicate

["prince","asish",5].concat(["ravi",4])

if you Want Without Duplicate you can try better Sol. from here - Shouting Code

a = [1,2,3];
b = 3].concat([3,2,1,"prince"];

a.concat(b"prince"].filter(function(el) {
        return a[1,2,3].indexOf(el) === -1;
    }));

Try On Chrome Browser Console

 f12 > console 

OutPut:

["prince", "asish", 5, "ravi", 4]

[1, 2, 3, "prince"]

Its Working fine a.concat(b); With Duplicate

you can check directly in browser Console by hitting...

["prince","asish",5].concat(["ravi",4])

if you Want Without Duplicate you can try better Sol. from here - Shouting Code

a = [1,2,3];
b = [3,2,1,"prince"];

a.concat(b.filter(function(el) {
        return a.indexOf(el) === -1;
    }));

Try On Chrome Browser Console

 f12 > console 

OutPut:

["prince", "asish", 5, "ravi", 4]

[1, 2, 3, "prince"]

Best Solution....

you can check directly in browser Console by hitting...

Without Duplicate

a = [1,2,3];
b = [3,2,1,"prince"];

a.concat(b.filter(function(el) {
        return a.indexOf(el) === -1;
    }));

With Duplicate

["prince","asish",5].concat(["ravi",4])

if you Want Without Duplicate you can try better Sol. from here - Shouting Code

[1,2,3].concat([3,2,1,"prince"].filter(function(el) {
        return [1,2,3].indexOf(el) === -1;
    }));

Try On Chrome Browser Console

 f12 > console 

OutPut:

["prince", "asish", 5, "ravi", 4]

[1, 2, 3, "prince"]
added 281 characters in body
Source Link
Zigri2612
  • 2.3k
  • 21
  • 33

Its Working fine a.concat(b); With Duplicate

you can check directly in browser Console by hitting...

["prince","asish",5].concat(["ravi",4])

on browser console f12 > consoleif you Want Without Duplicate you can try better Sol. from here - Shouting Code

a = [1,2,3];
b = [3,2,1,"prince"];

a.concat(b.filter(function(el) {
        return a.indexOf(el) === -1;
    }));

Try On Chrome Browser Console

 f12 > console 

OutPut:

["prince", "asish", 5, "ravi", 4]

[1, 2, 3, "prince"]

Its Working fine a.concat(b);

you can check directly in browser Console by hitting...

["prince","asish",5].concat(["ravi",4])

on browser console f12 > console

OutPut:

["prince", "asish", 5, "ravi", 4]

Its Working fine a.concat(b); With Duplicate

you can check directly in browser Console by hitting...

["prince","asish",5].concat(["ravi",4])

if you Want Without Duplicate you can try better Sol. from here - Shouting Code

a = [1,2,3];
b = [3,2,1,"prince"];

a.concat(b.filter(function(el) {
        return a.indexOf(el) === -1;
    }));

Try On Chrome Browser Console

 f12 > console 

OutPut:

["prince", "asish", 5, "ravi", 4]

[1, 2, 3, "prince"]
Source Link
Zigri2612
  • 2.3k
  • 21
  • 33
Loading