Is There Some Way I Can Join The Contents Of Two Javascript Arrays Much Like I

Is there some way I can "join" the contents of two javascript arrays much like I would do a join in SQL

Tags: javascript , sql Answers: 1 | Viewed 34,193 times



I have two arrays: Question and UserProfile



  • The userProfiles: [] array contain { id, name } objects

  • The questions: [] array contains { id, text, createdBy } objects


The createdBy integer in questions is always one of the id values in userProfiles.


Is there a way I could "join" the arrays in much the same way as I would join up two SQL tables if I was using a database.


What I need as an end result is an array that contains


{ id, text, name }

Corresponding SQL would be:


SELECT u.id, q.text, u.name 
FROM userProfiles u
JOIN questions q ON q.createdBy=u.id

Some Answers For Is There Some Way I Can Join The Contents Of Two Javascript Arrays Much Like I

#1. How to Join or Combine Two JavaScript Arrays by Concatenating Them …


const a = ['a', 'b', 'c'];
const b = ['d', 'e', 'f'];
const c = a.concat(b);
console.log(c)
["a", "b", "c", "d", "e", "f"]
const a = ['a', 'b', 'c'];
const b = ['d', 'e', 'f'];
const c = [...a, ...b]
console.log(c)
["a", "b", "c", "d", "e", "f"]

Please leave your answer here: