[英]How to use foreach loop in an array object variable using javascript
I have declared array
object
variable which is ordered_items
and it seems to be fine.我已经声明了array
object
变量,它是ordered_items
,它似乎很好。 But now how can I retrieve every item inside the object variable using foreach loop
in javascript.但是现在如何使用 javascript 中的foreach loop
检索 object 变量中的每个项目。 Thanks in advance.提前致谢。
var ordered_items = [];
for(var x = 0; x < prev_tbl_rows.length; x++){
var product = $(prev_tbl_rows[x]).find("td.one_prod_name").text();
var quantity = $(prev_tbl_rows[x]).find("td.one_qty").text();
var price = $(prev_tbl_rows[x]).find("td.oneprice").text();
var subtotal = $(prev_tbl_rows[x]).find("td.oneSubtotal").text();
ordered_items.push({
product: product,
quantity: quantity,
price: price,
subtotal: subtotal,
});
}
console.log(ordered_items);
//I don't have an idea how to retrieve each item inside this variable /*ordered_items*/
You mean this?你是这个意思?
let ordered_items = []; $("someSelectorForPrevRows").each(function() { $row = $(this); ordered_items.push({ product: $row.find("td.one_prod_name").text(), quantity: +$row.find("td.one_qty").text(), price: +$row.find("td.oneprice").text(), subtotal: +$row.find("td.oneSubtotal").text() }) }) ordered_items.forEach(item => console.log(item.product, item.quantity, item.price, item.subtotal)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.