How to join or combine two arrays to concatenate into one array?

JavaScript Joins - How to join two arrays in JavaScript?

How to join or combine two arrays to concatenate into one array?

The Example for “Join Two Arrays” in JavaScript as,

<!DOCTYPE html>

  <meta charset="utf-8" />
  <link rel="stylesheet" href="style.css" />
  <script data-require="jquery" data-semver="3.1.1" src=""></script>
    var users = [{
      id: 1,name: "Anil SIngh"}, {id: 2,name: "Alok"}, {
      id: 3,name: "Dilip"}, {id: 4, name: "Aradhya" }];

    var questions = [{
      id: 1, text: "70%", ques_user_id: 2 }, {
      id: 2,text: "71%",ques_user_id: 2 }, {
      id: 3,text: "58%", ques_user_id: 1 }, {
      id: 4,text: "68%",ques_user_id: 2}, {
      id: 5,text: "82%", ques_user_id: 3}, {
      id: 6,text: "55%",ques_user_id: 3 }];

    var joins = innerJoin(users, questions, function(user, question) {
      if (question.ques_user_id === {
        return {
          id:,  text: question.text,  name:

    function innerJoin(a, b, select) {
      var m = a.length,
        n = b.length,
        c = [];

      for (var i = 0; i < m; i++) {
        var x = a[i];

        for (var j = 0; j < n; j++) { // cartesian product - all combinations
          var y = select(x, b[j]); // filter out the rows and columns you want
          if (y) c.push(y); // if a row is returned add it to the table

      return c;


  <h1>How to join two objects in javascript?</h1>


The Result as,

I hope you are enjoying with this post! Please share with you friends. Thank you so much!

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
Post a Comment Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book