![](/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.