如何从数组中提取对象并将其放入根据对象对应的数组索引创建的变量中
我试过了:
response.forEach((el, i, )=>{
let nameProduct[i] = ` the name of product : ${response[i].nameProduct}`;
console.log(nameProduct[i]);
});
但是失败了
最佳答案
您可以将值映射到全局(或至少在 map
之外)变量。
const nameProduct = response.map(({ nameProduct }) => `the name of product: ${nameProduct}`);
关于javascript - 如何从数组中提取对象并自动将它们放入变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63966441/