我想知道如果没有一个或任何其他功能map,这个初步代码是否可行reduce?
const arr1 = ['str', 'str2'];
let obj = {};
Object.assign(obj, [...arr1] : 'Value');
console.log(obj); // Expected output: { str1: 'Value', str2: 'Value' }
Run Code Online (Sandbox Code Playgroud)
重点是将每个数组元素转换为一个对象键并为其分配一个静态值,引起我注意的是,是否可以通过使用简单的语法并将该数组解构为与伪代码类似?由于我找不到任何关于此的信息,我只想把这个问题清除掉.