Merging array entries referenced by indexes in another array I have one question list (q_arr) and the user can either skip or attempt that question. In the end of last question, I display all question with their selected answer and "N/A"  if not attempted.

Attempted question list is r_arr, where q property is the question number from q_arr list (q:1 means the first element of q_arr).



    (function() {
    
    let r_arr = [{q:1, a:true},{q:3, a:false}];
    let q_arr = [
                { q: 'one', o: [true, false] },
                { q: 'two', o: [true, false] },
                { q: 'three', o: [true, false] },
                { q: 'four', o: [true, false] }
            ];
    
    
    //desired output: [{q:"one", a: true}, {q:"two", a: "N/A"}, {q:"three", a: false}, {q:"four", a:"N/A"}]
    
    
    let op = q_arr.filter((s, idx, arr) =&gt; {
        // console.log("s", s, idx, arr);
        let id = idx + 1;
        r_arr.map((f) =&gt; {
            if (id === f.q) {
                f.q = s.q;
            }
        });
    });
    
    
    console.log("r_arr", r_arr); 
    })();




Now I again need to filter with q_arr and change to get not attempted question list and merge with this new r_arr and this seems a lengthy way.

Kindly suggest a way to solve this problem in fewer lines in ES6.
If you index the answers to the index of the questions you can do this:



let r_arr = {
            0: true,
            3: false
};
let q_arr = [
            { q: 'some question one', o: [true, false] },
            { q: 'some question two', o: [true, false] },
            { q: 'some question three', o: [true, false] },
            { q: 'some question four', o: [true, false] }
        ];

var a = q_arr.map((q, i) =&gt; ({'q': q.q, 'o': i in r_arr ? r_arr[i]  : 'na'}) )
console.log(a)




You'll need to account for the fact that js arrays are zero indexed.