[英]How to extract the objects from an array to put them in variables automatically?
How to extract the objects from an array to put them in variables that are created according to the index of the array that corresponds to the object如何从数组中提取对象并将它们放入根据对象对应的数组索引创建的变量中
I tried it :我尝试过这个 :
response.forEach((el, i, )=>{ let nameProduct[i] = ` the name of product : ${response[i].nameProduct}`; console.log(nameProduct[i]); });
but it's a fail但这是一个失败
您可以将值映射到全局(或至少在map
之外)变量。
const nameProduct = response.map(({ nameProduct }) => `the name of product: ${nameProduct}`);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.