From this order object, I want to extract a particular property from each of the objects in the products array.
var order = {
"products": [
{
"product_name":"Name",
"product_sku":"000000075266",
"pricesUnformatted":5130,
"prices":"5.130 EUR",
"subtotal":5130,
"subtotal_tax_amount":0,
"subtotal_discount":0,
"subtotal_with_tax":5130,
"quantity":18
},
{
"product_name":"Name2",
"product_sku":"000000072312",
"pricesUnformatted":369,
"prices":"369 EUR",
"subtotal":369,
"subtotal_tax_amount":0,
"subtotal_discount":0,
"subtotal_with_tax":369,
"quantity":1
}
],
"totalProduct":19,
"billTotal":"<div class='cart_left'>TotalPrice<\/div> : <strong>6.826 EUR<\/strong>",
"dataValidated":false,
"totalProductTxt":"<div class='cart_left'>Quantity<\/div> <div class='cart_right'><strong>19<\/strong><\/div>"
}
So from this object I want to get the “subtotal_with_tax” items and than SUM them and of course print the result because the “billTotal” contains the shipping price which I don’t need and I can’t modify the code before I get this object.
I tryed to make it work but I’m stuck at This point because I don’t know how to target a specific item’s value like in this case “subtotal_with_tax” :
$.each(order.products, function(key, val) {
$.each(val, function(key, val) {});
});
As @eicto said, if you only care about browsers that support it, or are using a “polyfill” for
map(), or ES5 methods in general, in other browsers, by all means usemap():