While working on a project for a client, I encountered an interesting problem. I have two arrays - one with objects and one with values. The task is to populate the array of objects with new objects for every item in the value array. To clarify, here is the code snippet and the expected output:
// Arrays: worksheet and data
var worksheet = [{"student_name": "Test 1", "file": "some_file_name.txt"}, {"student_name": "Test 3", "file": "some_file_name.txt"}]
var data = {"student_names": ["Test 1", "Test 2", "Test 3", "Test 4"]}
The goal is to iterate through data.student_names and add students that are not already in the worksheet.
// Expected Output:
var worksheet = [
{"student_name": "Test 1", "file": "some_file_name.txt"},
{"student_name": "Test 3", "file": "some_file_name.txt"},
{"student_name": "Test 2", "file": ""}, // New student
{"student_name": "Test 4", "file": ""}, // New student
]