我試圖從表單元素創建對象。出於某種原因,它正在拋出錯誤。減少功能與空對象不工作
let allInputs = [...formData];
allInputs.pop(); //Remove submit button
return allInputs.reduce((userObj, data) => userObj[`${data.name}`] = data.value, {});
錯誤
userModel.js:17 Uncaught TypeError: Cannot create property 'last_name' on string ''
似乎'userObj'是一個字符串? –
'reduce'回調需要返回累加器。 – loganfsmyth