-3
var array= [
    {
      "Name": "mohan",
      "DESCRIPTION": "Vendor"
    },
    {
      "Name": "mahesh",
      "DESCRIPTION": "Vendor1"
    },
    {
       "Name": "manoj",
      "DESCRIPTION": "Vendor2"
    }]

var array2= [
    {
      "Name": "mohanraj",
      "DESCRIPTION": "Vendor1"
    },
    {
      "Name": "manojkumar",
      "DESCRIPTION": "Vendor2"
    },
    {
       "Name": "mohankumar",
      "DESCRIPTION": "Vendor3"
    }];

expected output

array3=[
 {
      "Name": "mohan",
      "DESCRIPTION": "Vendor"
    },
    {
      "Name": "mahesh",
      "DESCRIPTION": "Vendor1"
    },
    {
       "Name": "manoj",
      "DESCRIPTION": "Vendor2"
    },
{
      "Name": "mohanraj",
      "DESCRIPTION": "Vendor1"
    },
    {
      "Name": "manojkumar",
      "DESCRIPTION": "Vendor2"
    },
    {
       "Name": "mohankumar",
      "DESCRIPTION": "Vendor3"
    }
];
Anatoly
  • 20,799
  • 3
  • 28
  • 42
Mohan Raj
  • 11
  • 5

6 Answers6

1

You can do it like this

const arraymain = [
    {
      "Name": "mohan",
      "DESCRIPTION": "Vendor"
    },
    {
      "Name": "mahesh",
      "DESCRIPTION": "Vendor1"
    },
    {
       "Name": "manoj",
      "DESCRIPTION": "Vendor2"
    }]
const arraysecond = [
    {
      "Name": "mohanraj",
      "DESCRIPTION": "Vendor1"
    },
    {
      "Name": "manojkumar",
      "DESCRIPTION": "Vendor2"
    },
    {
       "Name": "mohankumar",
      "DESCRIPTION": "Vendor3"
    }];
const arraythird = array3=[
 {
      "Name": "mohan",
      "DESCRIPTION": "Vendor"
    },
    {
      "Name": "mahesh",
      "DESCRIPTION": "Vendor1"
    },
    {
       "Name": "manoj",
      "DESCRIPTION": "Vendor2"
    },
{
      "Name": "mohanraj",
      "DESCRIPTION": "Vendor1"
    },
    {
      "Name": "manojkumar",
      "DESCRIPTION": "Vendor2"
    },
    {
       "Name": "mohankumar",
      "DESCRIPTION": "Vendor3"
    }
];
const arrayfinal = arraymain.concat(arraysecond,arraythird);

console.log(arrayfinal);
Mohit Chandel
  • 1,838
  • 10
  • 31
0
const array3 = array1.concat(array2):

See Array.prototype.concat

Anatoly
  • 20,799
  • 3
  • 28
  • 42
0
const array3 = [...array1, ...array2]

this will do shallow copy, which will avoid reference issues upto a level.

0

You can Array.prototype.concat method which allows to append value of one array to another Array

let first_array = [1,2,3,4];
let second_array = [5,6,7,8];

let results = first_array.concat(second_array);
console.log(results);

In you case you can perform that this way

let array3 = array.concat(array2):
Yves Kipondo
  • 5,289
  • 1
  • 18
  • 31
0

The Array() constructor is used to create Array objects. You can create the third array by passing the elements of the first and second array elements as arguments. You could do that by using the spread operator.

let newArray = new Array(...firstArray, ...secondArray)
Shiyas
  • 570
  • 5
  • 11
  • Thank you for this code snippet, which might provide some limited, immediate help. A [proper explanation](https://meta.stackexchange.com/q/114762/349538) would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you've made. – wscourge Dec 01 '20 at 07:02
0

I think that it very important to take your time learning the basics of Javascript.There ar 1000 ways to achieve this.

var array= [
    {
      "Name": "mohan",
      "DESCRIPTION": "Vendor"
    },
    {
      "Name": "mahesh",
      "DESCRIPTION": "Vendor1"
    },
    {
       "Name": "manoj",
      "DESCRIPTION": "Vendor2"
    }]

var array2= [
    {
      "Name": "mohanraj",
      "DESCRIPTION": "Vendor1"
    },
    {
      "Name": "manojkumar",
      "DESCRIPTION": "Vendor2"
    },
    {
       "Name": "mohankumar",
      "DESCRIPTION": "Vendor3"
    }];

//Without ES6
var arr3=array.concat(array2)

//With ES6 syntax
cons arr3=[...arr,...arr2]

For the rest learn the basics of Javascript...

Christian LSANGOLA
  • 2,947
  • 4
  • 22
  • 36