function pick(obj, arr){ for(let i = 0; i < arr.length; i++) { obj[i] = arr[i]; } return obj; } var obj=[]; var arr = [1, 2]; pick(obj, arr) console.log("[" + obj + "]");