![](/img/trans.png)
[英]How to store an array of data in an array of objects in firestore using vue.js
[英]How to fetch particular data from array of objects and store in new array in js (vue js)
我有这个 object 数组
let detail : [
0: {
Code: "Code 1"
Price: "0.00"
},
1: {
Code: "Code 2"
Price: "9.00"
}
]
我想将价格存储在一个数组中(例如:结果),以便我可以将它与对象的另一个现有数组合并(例如:alldetail)
result = [
0: {
Price:"0.00"
},
1: {
Price:"9.00"
},
]
使用map()
方法创建一个新数组,该数组填充了提供的 function 在调用数组中的每个元素上执行的结果。
因此,在您的情况下,您将返回一个带有键 Price 的 object ,其值将是当前的 object 及其 Price 属性的值。
let detail = [ { Code: "Code 1", Price: "0.00" }, { Code: "Code 2", Price: "9.00" } ]; let result = detail.map(current => {return {Price: current.Price}}); console.log(result);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.