var course = ["HTML", "CSS", "JAVASCRIPT", "PYTHON"]
var student = { name: "john doe", course } { name: "gary lary", course }
I want the output to be group1 [html css javascript python] john doe is assigned html gary lary css and so on
var course = ["HTML", "CSS", "JAVASCRIPT", "PYTHON"]
var student = { name: "john doe", course } { name: "gary lary", course }
I want the output to be group1 [html css javascript python] john doe is assigned html gary lary css and so on
It depends on how you want to combine them. If you don't want to randomize courses to students, you can just match the index of the student with the course. You can use the map
array method:
let courses = ["HTML", "CSS", "JAVASCRIPT", "PYTHON"]
let students = [ {name: "john doe" },{ name: "gary lary"}]
const studendsWithCourses = students.map((student, index) => ({...student, course: courses[index]}))
Note that in this case you'll get an error if the array if students is bigger then the array of courses. You can fix this by changing the map to this:
const studendsWithCourses2 = students.map((student, index) => ({...student, course: courses[index % courses.length]}))
.
This way, courses will be distributed in order to students and you won't get an error if the students array is bigger than the courses array.