JSFiddle - React, Tailwind, and code Playground

JavaScript

var userProfiles = [{id:1, name:'name1'},{id:2,name:'name2'}];
    var questions = [
        {id:1, text:'text1', createdBy:'foo'},
        {id:1, text:'text2', createdBy:'bar'},
        {id:2, text:'text3', createdBy:'foo'}];
    
    merged = mergeMyArrays(userProfiles,questions);
    
    console.log(merged);
    /**
     * This will give you an array like this [{id:1, name:name1, questions:[{...}]]
     * params : 2 arrays to merge by id
     */
    function mergeMyArrays(u,q){
        var ret = [];
        for(var i = 0, l = u.length; i < l; i++){
            var curU = u[i],
                curId = curU.id,
                tmpObj = {id:curId, name:curU.name, questions:[]};
            for(var j = 0, m = q.length; j<m; j++){
                if(q[j].id == curId){
                    tmpObj.questions.push({text:q[j].text, createdBy:q[j].createdBy});
                }
            }
            ret.push(tmpObj);
        }
        return ret;
    }