简体   繁体   English

如何从数组中提取对象以自动将它们放入变量中?

[英]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.

相关问题 从字符串中提取3个数字并将其放入变量中 - Extract 3 numbers from string and put them into variables 如何提取嵌套的对象数组并将它们放入核心数组中? - How can I extract a nested array of objects and put them in the core array? 如何从一个数组中提取数组并将它们转换为对象并将它们放入一个新数组中? - how can i extract arrays from one array & convert them in object and put them in a new array? 如何从对象数组中提取数据并分配给变量? - How do i extract data from an array of objects and assign to variables? 从对象数组中收集数据并将它们放入新的对象数组中 - collecting data from an array of objects & put them in a new array of objects 如何仅从对象数组中提取值并使用 react 和 javascript 将其放入数组中? - How to extract only values from array of objects and put it to an array using react and javascript? 如何提取此类数据并将其放入一个不错的数组中? - how to extract this kind of data and put them into a nice array? 从对象数组中提取一个属性并用它们构建一个字符串 - From an array of objects, extract one property and build a string with them 如何找到特定的对象并将它们放在javascript中的数组中 - how to find specific objects and put them in an array in javascript 提取许多子字符串并将其放入JavaScript数组中 - Extract many substrings and put them into an array in JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM