skip to Main Content

I have a JSON and I need to get SKU attribute value as a result array. The SKU attribute will be inside of shipping and OFSUC arrays. So I am trying to get those values efficiently using a filter or map function in JS but I don’t know how to iterate more than one array.

My JSON Object

{
"id": 103,
"consignments": [
    {
        "pickups": [],
        "shipping": [
            {
                "id": 4,
                "first_name": "Sabareesh",
                "line_items": [
                    {
                        "id": 5,
                        "order_id": 103,
                        "product_id": 86,
                        "variant_id": 66,
                        "order_pickup_method_id": 0,
                        "order_address_id": 4,
                        "name": "[Sample] Able Brewing System",
                        "name_customer": "[Sample] Able Brewing System",
                        "name_merchant": "[Sample] Able Brewing System",
                        "sku": "ABS",
                        "upc": "",
                        "type": "physical",
                        "base_price": "225.0000",
                        "price_ex_tax": "225.0000",
                        "price_inc_tax": "270.0000",
                        "price_tax": "45.0000",
                        "base_total": "225.0000",
                        "total_ex_tax": "225.0000",
                        "total_inc_tax": "270.0000",
                        "total_tax": "45.0000",
                        "weight": "1.0000",
                        "width": "10.0000",
                        "height": "10.0000",
                        "depth": "10.0000",
                        "quantity": 1,
                        "base_cost_price": "0.0000",
                        "cost_price_inc_tax": "0.0000",
                        "cost_price_ex_tax": "0.0000",
                        "cost_price_tax": "0.0000",
                        "is_refunded": false,
                        "quantity_refunded": 0,
                        "refund_amount": "0.0000",
                        "return_id": 0,
                        "wrapping_id": 0,
                        "wrapping_name": "",
                        "base_wrapping_cost": "0.0000",
                        "wrapping_cost_ex_tax": "0.0000",
                        "wrapping_cost_inc_tax": "0.0000",
                        "wrapping_cost_tax": "0.0000",
                        "wrapping_message": "",
                        "quantity_shipped": 0,
                        "event_name": null,
                        "event_date": "",
                        "fixed_shipping_cost": "0.0000",
                        "ebay_item_id": "",
                        "ebay_transaction_id": "",
                        "option_set_id": null,
                        "parent_order_product_id": null,
                        "is_bundled_product": false,
                        "bin_picking_number": "",
                        "external_id": null,
                        "fulfillment_source": "",
                        "brand": "",
                        "gift_certificate_id": null,
                        "applied_discounts": [],
                        "product_options": [],
                        "configurable_fields": [],
                        "discounted_total_inc_tax": "270.0000"
                    },
                    {
                        "id": 14,
                        "order_id": 103,
                        "product_id": 94,
                        "variant_id": 68,
                        "order_pickup_method_id": 0,
                        "order_address_id": 4,
                        "name": "[Sample] Oak Cheese Grater",
                        "name_customer": "[Sample] Oak Cheese Grater",
                        "name_merchant": "[Sample] Oak Cheese Grater",
                        "sku": "OCG",
                        "upc": "",
                        "type": "physical",
                        "base_price": "31.4600",
                        "price_ex_tax": "31.4600",
                        "price_inc_tax": "37.7500",
                        "price_tax": "6.2900",
                        "base_total": "31.4600",
                        "total_ex_tax": "31.4600",
                        "total_inc_tax": "37.7500",
                        "total_tax": "6.2900",
                        "weight": "1.0000",
                        "width": "0.0000",
                        "height": "0.0000",
                        "depth": "0.0000",
                        "quantity": 1,
                        "base_cost_price": "0.0000",
                        "cost_price_inc_tax": "0.0000",
                        "cost_price_ex_tax": "0.0000",
                        "cost_price_tax": "0.0000",
                        "is_refunded": false,
                        "quantity_refunded": 0,
                        "refund_amount": "0.0000",
                        "return_id": 0,
                        "wrapping_id": 0,
                        "wrapping_name": "",
                        "base_wrapping_cost": "0.0000",
                        "wrapping_cost_ex_tax": "0.0000",
                        "wrapping_cost_inc_tax": "0.0000",
                        "wrapping_cost_tax": "0.0000",
                        "wrapping_message": "",
                        "quantity_shipped": 0,
                        "event_name": null,
                        "event_date": "",
                        "fixed_shipping_cost": "0.0000",
                        "ebay_item_id": "",
                        "ebay_transaction_id": "",
                        "option_set_id": null,
                        "parent_order_product_id": null,
                        "is_bundled_product": false,
                        "bin_picking_number": "",
                        "external_id": null,
                        "fulfillment_source": "",
                        "brand": "Sagaform",
                        "gift_certificate_id": null,
                        "applied_discounts": [],
                        "product_options": [],
                        "configurable_fields": [],
                        "discounted_total_inc_tax": "37.7500"
                    }
                ],
                "items_total": 2,
                "items_shipped": 0,
                "shipping_method": "Free Shipping",
                "base_cost": 0,
                "cost_ex_tax": 0,
                "cost_inc_tax": 0,
                "cost_tax": 0,
                "cost_tax_class_id": 2,
                "base_handling_cost": 0,
                "handling_cost_ex_tax": 0,
                "handling_cost_inc_tax": 0,
                "handling_cost_tax": 0,
                "handling_cost_tax_class_id": 2,
                "shipping_zone_id": 2,
                "shipping_zone_name": "Qatar"      
            }
        ],
        "downloads": [
            {
                "line_items": [
                    {
                        "id": 15,
                        "order_id": 103,
                        "product_id": 104,
                        "variant_id": 72,
                        "order_pickup_method_id": 0,
                        "order_address_id": 0,
                        "name": "[Sample] Utility Caddy",
                        "name_customer": "[Sample] Utility Caddy",
                        "name_merchant": "[Sample] Utility Caddy",
                        "sku": "OFSUC",
                        "upc": "",
                        "type": "digital",
                        "base_price": "41.3600",
                        "price_ex_tax": "41.3600",
                        "price_inc_tax": "49.6300",
                        "price_tax": "8.2700",
                        "base_total": "41.3600",
                        "total_ex_tax": "41.3600",
                        "total_inc_tax": "49.6300",
                        "total_tax": "8.2700",
                        "weight": "0.0000",
                        "width": "0.0000",
                        "height": "0.0000",
                        "depth": "0.0000",
                        "quantity": 1,
                        "base_cost_price": "0.0000",
                        "cost_price_inc_tax": "0.0000",
                        "cost_price_ex_tax": "0.0000",
                        "cost_price_tax": "0.0000",
                        "is_refunded": false,
                        "quantity_refunded": 0,
                        "refund_amount": "0.0000",
                        "return_id": 0,
                        "wrapping_id": 0,
                        "wrapping_name": "",
                        "base_wrapping_cost": "0.0000",
                        "wrapping_cost_ex_tax": "0.0000",
                        "wrapping_cost_inc_tax": "0.0000",
                        "wrapping_cost_tax": "0.0000",
                        "wrapping_message": "",
                        "quantity_shipped": 0,
                        "event_name": null,
                        "event_date": "",
                        "fixed_shipping_cost": "0.0000",
                        "ebay_item_id": "",
                        "ebay_transaction_id": "",
                        "option_set_id": null,
                        "parent_order_product_id": null,
                        "is_bundled_product": false,
                        "bin_picking_number": "",
                        "external_id": null,
                        "fulfillment_source": "",
                        "brand": "OFS",
                        "gift_certificate_id": null,
                        "applied_discounts": [],
                        "product_options": [],
                        "configurable_fields": [],
                        "discounted_total_inc_tax": "49.6300"
                    }
                ]
            }
        ],
        "email": {
            "gift_certificates": []
        }
    }
]

}

Expected result:
["OCG", "ABS", "OFSUC"]

3

Answers


  1. You can try the following way:

    const jsonObject={id:103,consignments:[{pickups:[],shipping:[{id:4,first_name:"Sabareesh",line_items:[{id:5,order_id:103,product_id:86,variant_id:66,order_pickup_method_id:0,order_address_id:4,name:"[Sample] Able Brewing System",name_customer:"[Sample] Able Brewing System",name_merchant:"[Sample] Able Brewing System",sku:"ABS",upc:"",type:"physical",base_price:"225.0000",price_ex_tax:"225.0000",price_inc_tax:"270.0000",price_tax:"45.0000",base_total:"225.0000",total_ex_tax:"225.0000",total_inc_tax:"270.0000",total_tax:"45.0000",weight:"1.0000",width:"10.0000",height:"10.0000",depth:"10.0000",quantity:1,base_cost_price:"0.0000",cost_price_inc_tax:"0.0000",cost_price_ex_tax:"0.0000",cost_price_tax:"0.0000",is_refunded:!1,quantity_refunded:0,refund_amount:"0.0000",return_id:0,wrapping_id:0,wrapping_name:"",base_wrapping_cost:"0.0000",wrapping_cost_ex_tax:"0.0000",wrapping_cost_inc_tax:"0.0000",wrapping_cost_tax:"0.0000",wrapping_message:"",quantity_shipped:0,event_name:null,event_date:"",fixed_shipping_cost:"0.0000",ebay_item_id:"",ebay_transaction_id:"",option_set_id:null,parent_order_product_id:null,is_bundled_product:!1,bin_picking_number:"",external_id:null,fulfillment_source:"",brand:"",gift_certificate_id:null,applied_discounts:[],product_options:[],configurable_fields:[],discounted_total_inc_tax:"270.0000"},{id:14,order_id:103,product_id:94,variant_id:68,order_pickup_method_id:0,order_address_id:4,name:"[Sample] Oak Cheese Grater",name_customer:"[Sample] Oak Cheese Grater",name_merchant:"[Sample] Oak Cheese Grater",sku:"OCG",upc:"",type:"physical",base_price:"31.4600",price_ex_tax:"31.4600",price_inc_tax:"37.7500",price_tax:"6.2900",base_total:"31.4600",total_ex_tax:"31.4600",total_inc_tax:"37.7500",total_tax:"6.2900",weight:"1.0000",width:"0.0000",height:"0.0000",depth:"0.0000",quantity:1,base_cost_price:"0.0000",cost_price_inc_tax:"0.0000",cost_price_ex_tax:"0.0000",cost_price_tax:"0.0000",is_refunded:!1,quantity_refunded:0,refund_amount:"0.0000",return_id:0,wrapping_id:0,wrapping_name:"",base_wrapping_cost:"0.0000",wrapping_cost_ex_tax:"0.0000",wrapping_cost_inc_tax:"0.0000",wrapping_cost_tax:"0.0000",wrapping_message:"",quantity_shipped:0,event_name:null,event_date:"",fixed_shipping_cost:"0.0000",ebay_item_id:"",ebay_transaction_id:"",option_set_id:null,parent_order_product_id:null,is_bundled_product:!1,bin_picking_number:"",external_id:null,fulfillment_source:"",brand:"Sagaform",gift_certificate_id:null,applied_discounts:[],product_options:[],configurable_fields:[],discounted_total_inc_tax:"37.7500"}],items_total:2,items_shipped:0,shipping_method:"Free Shipping",base_cost:0,cost_ex_tax:0,cost_inc_tax:0,cost_tax:0,cost_tax_class_id:2,base_handling_cost:0,handling_cost_ex_tax:0,handling_cost_inc_tax:0,handling_cost_tax:0,handling_cost_tax_class_id:2,shipping_zone_id:2,shipping_zone_name:"Qatar"}],downloads:[{line_items:[{id:15,order_id:103,product_id:104,variant_id:72,order_pickup_method_id:0,order_address_id:0,name:"[Sample] Utility Caddy",name_customer:"[Sample] Utility Caddy",name_merchant:"[Sample] Utility Caddy",sku:"OFSUC",upc:"",type:"digital",base_price:"41.3600",price_ex_tax:"41.3600",price_inc_tax:"49.6300",price_tax:"8.2700",base_total:"41.3600",total_ex_tax:"41.3600",total_inc_tax:"49.6300",total_tax:"8.2700",weight:"0.0000",width:"0.0000",height:"0.0000",depth:"0.0000",quantity:1,base_cost_price:"0.0000",cost_price_inc_tax:"0.0000",cost_price_ex_tax:"0.0000",cost_price_tax:"0.0000",is_refunded:!1,quantity_refunded:0,refund_amount:"0.0000",return_id:0,wrapping_id:0,wrapping_name:"",base_wrapping_cost:"0.0000",wrapping_cost_ex_tax:"0.0000",wrapping_cost_inc_tax:"0.0000",wrapping_cost_tax:"0.0000",wrapping_message:"",quantity_shipped:0,event_name:null,event_date:"",fixed_shipping_cost:"0.0000",ebay_item_id:"",ebay_transaction_id:"",option_set_id:null,parent_order_product_id:null,is_bundled_product:!1,bin_picking_number:"",external_id:null,fulfillment_source:"",brand:"OFS",gift_certificate_id:null,applied_discounts:[],product_options:[],configurable_fields:[],discounted_total_inc_tax:"49.6300"}]}],email:{gift_certificates:[]}}]};
    
    
    //use flatMap to iterate over consignments array
    const skuArray = jsonObject.consignments.flatMap((consignment) =>
      //concatenate sku values from shipping and downloads arrays
      consignment.shipping.concat(consignment.downloads)
        //flatten the nested arrays and extract sku values
        .flatMap((item) => item.line_items.flatMap((subItem) => subItem.sku))
    );
    
    
    console.log(skuArray);
    Login or Signup to reply.
  2. If you need to extract all values of the property sku anywhere deep in a given object, you may iterate over the properties of an object recursively and return the values mapped to it:

    function findAllSKUs(obj) {
        let skus = [];
    
        function search(obj) {
            if (obj !== null && typeof obj === 'object') {
                Object.entries(obj).forEach(([key, value]) => {
                    if (key === 'sku' && typeof value === 'string') {
                        skus.push(value);
                    } else {
                        search(value);
                    }
                });
            }
        }
    
        search(obj);
        return skus;
    }
    
    const data =
    {
    "id": 103,
    "consignments": [
        {
            "pickups": [],
            "shipping": [
                {
                    "id": 4,
                    "first_name": "Sabareesh",
                    "line_items": [
                        {
                            "id": 5,
                            "order_id": 103,
                            "product_id": 86,
                            "variant_id": 66,
                            "order_pickup_method_id": 0,
                            "order_address_id": 4,
                            "name": "[Sample] Able Brewing System",
                            "name_customer": "[Sample] Able Brewing System",
                            "name_merchant": "[Sample] Able Brewing System",
                            "sku": "ABS",
                            "upc": "",
                            "type": "physical",
                            "base_price": "225.0000",
                            "price_ex_tax": "225.0000",
                            "price_inc_tax": "270.0000",
                            "price_tax": "45.0000",
                            "base_total": "225.0000",
                            "total_ex_tax": "225.0000",
                            "total_inc_tax": "270.0000",
                            "total_tax": "45.0000",
                            "weight": "1.0000",
                            "width": "10.0000",
                            "height": "10.0000",
                            "depth": "10.0000",
                            "quantity": 1,
                            "base_cost_price": "0.0000",
                            "cost_price_inc_tax": "0.0000",
                            "cost_price_ex_tax": "0.0000",
                            "cost_price_tax": "0.0000",
                            "is_refunded": false,
                            "quantity_refunded": 0,
                            "refund_amount": "0.0000",
                            "return_id": 0,
                            "wrapping_id": 0,
                            "wrapping_name": "",
                            "base_wrapping_cost": "0.0000",
                            "wrapping_cost_ex_tax": "0.0000",
                            "wrapping_cost_inc_tax": "0.0000",
                            "wrapping_cost_tax": "0.0000",
                            "wrapping_message": "",
                            "quantity_shipped": 0,
                            "event_name": null,
                            "event_date": "",
                            "fixed_shipping_cost": "0.0000",
                            "ebay_item_id": "",
                            "ebay_transaction_id": "",
                            "option_set_id": null,
                            "parent_order_product_id": null,
                            "is_bundled_product": false,
                            "bin_picking_number": "",
                            "external_id": null,
                            "fulfillment_source": "",
                            "brand": "",
                            "gift_certificate_id": null,
                            "applied_discounts": [],
                            "product_options": [],
                            "configurable_fields": [],
                            "discounted_total_inc_tax": "270.0000"
                        },
                        {
                            "id": 14,
                            "order_id": 103,
                            "product_id": 94,
                            "variant_id": 68,
                            "order_pickup_method_id": 0,
                            "order_address_id": 4,
                            "name": "[Sample] Oak Cheese Grater",
                            "name_customer": "[Sample] Oak Cheese Grater",
                            "name_merchant": "[Sample] Oak Cheese Grater",
                            "sku": "OCG",
                            "upc": "",
                            "type": "physical",
                            "base_price": "31.4600",
                            "price_ex_tax": "31.4600",
                            "price_inc_tax": "37.7500",
                            "price_tax": "6.2900",
                            "base_total": "31.4600",
                            "total_ex_tax": "31.4600",
                            "total_inc_tax": "37.7500",
                            "total_tax": "6.2900",
                            "weight": "1.0000",
                            "width": "0.0000",
                            "height": "0.0000",
                            "depth": "0.0000",
                            "quantity": 1,
                            "base_cost_price": "0.0000",
                            "cost_price_inc_tax": "0.0000",
                            "cost_price_ex_tax": "0.0000",
                            "cost_price_tax": "0.0000",
                            "is_refunded": false,
                            "quantity_refunded": 0,
                            "refund_amount": "0.0000",
                            "return_id": 0,
                            "wrapping_id": 0,
                            "wrapping_name": "",
                            "base_wrapping_cost": "0.0000",
                            "wrapping_cost_ex_tax": "0.0000",
                            "wrapping_cost_inc_tax": "0.0000",
                            "wrapping_cost_tax": "0.0000",
                            "wrapping_message": "",
                            "quantity_shipped": 0,
                            "event_name": null,
                            "event_date": "",
                            "fixed_shipping_cost": "0.0000",
                            "ebay_item_id": "",
                            "ebay_transaction_id": "",
                            "option_set_id": null,
                            "parent_order_product_id": null,
                            "is_bundled_product": false,
                            "bin_picking_number": "",
                            "external_id": null,
                            "fulfillment_source": "",
                            "brand": "Sagaform",
                            "gift_certificate_id": null,
                            "applied_discounts": [],
                            "product_options": [],
                            "configurable_fields": [],
                            "discounted_total_inc_tax": "37.7500"
                        }
                    ],
                    "items_total": 2,
                    "items_shipped": 0,
                    "shipping_method": "Free Shipping",
                    "base_cost": 0,
                    "cost_ex_tax": 0,
                    "cost_inc_tax": 0,
                    "cost_tax": 0,
                    "cost_tax_class_id": 2,
                    "base_handling_cost": 0,
                    "handling_cost_ex_tax": 0,
                    "handling_cost_inc_tax": 0,
                    "handling_cost_tax": 0,
                    "handling_cost_tax_class_id": 2,
                    "shipping_zone_id": 2,
                    "shipping_zone_name": "Qatar"      
                }
            ],
            "downloads": [
                {
                    "line_items": [
                        {
                            "id": 15,
                            "order_id": 103,
                            "product_id": 104,
                            "variant_id": 72,
                            "order_pickup_method_id": 0,
                            "order_address_id": 0,
                            "name": "[Sample] Utility Caddy",
                            "name_customer": "[Sample] Utility Caddy",
                            "name_merchant": "[Sample] Utility Caddy",
                            "sku": "OFSUC",
                            "upc": "",
                            "type": "digital",
                            "base_price": "41.3600",
                            "price_ex_tax": "41.3600",
                            "price_inc_tax": "49.6300",
                            "price_tax": "8.2700",
                            "base_total": "41.3600",
                            "total_ex_tax": "41.3600",
                            "total_inc_tax": "49.6300",
                            "total_tax": "8.2700",
                            "weight": "0.0000",
                            "width": "0.0000",
                            "height": "0.0000",
                            "depth": "0.0000",
                            "quantity": 1,
                            "base_cost_price": "0.0000",
                            "cost_price_inc_tax": "0.0000",
                            "cost_price_ex_tax": "0.0000",
                            "cost_price_tax": "0.0000",
                            "is_refunded": false,
                            "quantity_refunded": 0,
                            "refund_amount": "0.0000",
                            "return_id": 0,
                            "wrapping_id": 0,
                            "wrapping_name": "",
                            "base_wrapping_cost": "0.0000",
                            "wrapping_cost_ex_tax": "0.0000",
                            "wrapping_cost_inc_tax": "0.0000",
                            "wrapping_cost_tax": "0.0000",
                            "wrapping_message": "",
                            "quantity_shipped": 0,
                            "event_name": null,
                            "event_date": "",
                            "fixed_shipping_cost": "0.0000",
                            "ebay_item_id": "",
                            "ebay_transaction_id": "",
                            "option_set_id": null,
                            "parent_order_product_id": null,
                            "is_bundled_product": false,
                            "bin_picking_number": "",
                            "external_id": null,
                            "fulfillment_source": "",
                            "brand": "OFS",
                            "gift_certificate_id": null,
                            "applied_discounts": [],
                            "product_options": [],
                            "configurable_fields": [],
                            "discounted_total_inc_tax": "49.6300"
                        }
                    ]
                }
            ],
            "email": {
                "gift_certificates": []
            }
        }
    ]};
    
    const skus = findAllSKUs(data);
    console.log(skus);
    Login or Signup to reply.
  3. const obj = {
      id: 103,
      consignments: [
        {
          pickups: [],
          shipping: [
            {
              id: 4,
              first_name: "Sabareesh",
              line_items: [
                {
                  id: 5,
                  order_id: 103,
                  product_id: 86,
                  variant_id: 66,
                  order_pickup_method_id: 0,
                  order_address_id: 4,
                  name: "[Sample] Able Brewing System",
                  name_customer: "[Sample] Able Brewing System",
                  name_merchant: "[Sample] Able Brewing System",
                  sku: "ABS",
                  upc: "",
                  type: "physical",
                  base_price: "225.0000",
                  price_ex_tax: "225.0000",
                  price_inc_tax: "270.0000",
                  price_tax: "45.0000",
                  base_total: "225.0000",
                  total_ex_tax: "225.0000",
                  total_inc_tax: "270.0000",
                  total_tax: "45.0000",
                  weight: "1.0000",
                  width: "10.0000",
                  height: "10.0000",
                  depth: "10.0000",
                  quantity: 1,
                  base_cost_price: "0.0000",
                  cost_price_inc_tax: "0.0000",
                  cost_price_ex_tax: "0.0000",
                  cost_price_tax: "0.0000",
                  is_refunded: false,
                  quantity_refunded: 0,
                  refund_amount: "0.0000",
                  return_id: 0,
                  wrapping_id: 0,
                  wrapping_name: "",
                  base_wrapping_cost: "0.0000",
                  wrapping_cost_ex_tax: "0.0000",
                  wrapping_cost_inc_tax: "0.0000",
                  wrapping_cost_tax: "0.0000",
                  wrapping_message: "",
                  quantity_shipped: 0,
                  event_name: null,
                  event_date: "",
                  fixed_shipping_cost: "0.0000",
                  ebay_item_id: "",
                  ebay_transaction_id: "",
                  option_set_id: null,
                  parent_order_product_id: null,
                  is_bundled_product: false,
                  bin_picking_number: "",
                  external_id: null,
                  fulfillment_source: "",
                  brand: "",
                  gift_certificate_id: null,
                  applied_discounts: [],
                  product_options: [],
                  configurable_fields: [],
                  discounted_total_inc_tax: "270.0000",
                },
                {
                  id: 14,
                  order_id: 103,
                  product_id: 94,
                  variant_id: 68,
                  order_pickup_method_id: 0,
                  order_address_id: 4,
                  name: "[Sample] Oak Cheese Grater",
                  name_customer: "[Sample] Oak Cheese Grater",
                  name_merchant: "[Sample] Oak Cheese Grater",
                  sku: "OCG",
                  upc: "",
                  type: "physical",
                  base_price: "31.4600",
                  price_ex_tax: "31.4600",
                  price_inc_tax: "37.7500",
                  price_tax: "6.2900",
                  base_total: "31.4600",
                  total_ex_tax: "31.4600",
                  total_inc_tax: "37.7500",
                  total_tax: "6.2900",
                  weight: "1.0000",
                  width: "0.0000",
                  height: "0.0000",
                  depth: "0.0000",
                  quantity: 1,
                  base_cost_price: "0.0000",
                  cost_price_inc_tax: "0.0000",
                  cost_price_ex_tax: "0.0000",
                  cost_price_tax: "0.0000",
                  is_refunded: false,
                  quantity_refunded: 0,
                  refund_amount: "0.0000",
                  return_id: 0,
                  wrapping_id: 0,
                  wrapping_name: "",
                  base_wrapping_cost: "0.0000",
                  wrapping_cost_ex_tax: "0.0000",
                  wrapping_cost_inc_tax: "0.0000",
                  wrapping_cost_tax: "0.0000",
                  wrapping_message: "",
                  quantity_shipped: 0,
                  event_name: null,
                  event_date: "",
                  fixed_shipping_cost: "0.0000",
                  ebay_item_id: "",
                  ebay_transaction_id: "",
                  option_set_id: null,
                  parent_order_product_id: null,
                  is_bundled_product: false,
                  bin_picking_number: "",
                  external_id: null,
                  fulfillment_source: "",
                  brand: "Sagaform",
                  gift_certificate_id: null,
                  applied_discounts: [],
                  product_options: [],
                  configurable_fields: [],
                  discounted_total_inc_tax: "37.7500",
                },
              ],
              items_total: 2,
              items_shipped: 0,
              shipping_method: "Free Shipping",
              base_cost: 0,
              cost_ex_tax: 0,
              cost_inc_tax: 0,
              cost_tax: 0,
              cost_tax_class_id: 2,
              base_handling_cost: 0,
              handling_cost_ex_tax: 0,
              handling_cost_inc_tax: 0,
              handling_cost_tax: 0,
              handling_cost_tax_class_id: 2,
              shipping_zone_id: 2,
              shipping_zone_name: "Qatar",
            },
          ],
          downloads: [
            {
              line_items: [
                {
                  id: 15,
                  order_id: 103,
                  product_id: 104,
                  variant_id: 72,
                  order_pickup_method_id: 0,
                  order_address_id: 0,
                  name: "[Sample] Utility Caddy",
                  name_customer: "[Sample] Utility Caddy",
                  name_merchant: "[Sample] Utility Caddy",
                  sku: "OFSUC",
                  upc: "",
                  type: "digital",
                  base_price: "41.3600",
                  price_ex_tax: "41.3600",
                  price_inc_tax: "49.6300",
                  price_tax: "8.2700",
                  base_total: "41.3600",
                  total_ex_tax: "41.3600",
                  total_inc_tax: "49.6300",
                  total_tax: "8.2700",
                  weight: "0.0000",
                  width: "0.0000",
                  height: "0.0000",
                  depth: "0.0000",
                  quantity: 1,
                  base_cost_price: "0.0000",
                  cost_price_inc_tax: "0.0000",
                  cost_price_ex_tax: "0.0000",
                  cost_price_tax: "0.0000",
                  is_refunded: false,
                  quantity_refunded: 0,
                  refund_amount: "0.0000",
                  return_id: 0,
                  wrapping_id: 0,
                  wrapping_name: "",
                  base_wrapping_cost: "0.0000",
                  wrapping_cost_ex_tax: "0.0000",
                  wrapping_cost_inc_tax: "0.0000",
                  wrapping_cost_tax: "0.0000",
                  wrapping_message: "",
                  quantity_shipped: 0,
                  event_name: null,
                  event_date: "",
                  fixed_shipping_cost: "0.0000",
                  ebay_item_id: "",
                  ebay_transaction_id: "",
                  option_set_id: null,
                  parent_order_product_id: null,
                  is_bundled_product: false,
                  bin_picking_number: "",
                  external_id: null,
                  fulfillment_source: "",
                  brand: "OFS",
                  gift_certificate_id: null,
                  applied_discounts: [],
                  product_options: [],
                  configurable_fields: [],
                  discounted_total_inc_tax: "49.6300",
                },
              ],
            },
          ],
          email: {
            gift_certificates: [],
          },
        },
      ],
    };
    
    
    // START actual code
    const output = [];
    const helperFn = (arr) => {
      arr.map((i) => {
        i.line_items.map((l) => {
          output.push(l.sku);
        });
      });
    };
    obj.consignments.map((c) => {
      helperFn(c.pickups);
      helperFn(c.shipping);
      helperFn(c.downloads);
    });
    
    console.log("Output: ", output);
    // Output: ['ABS', 'OCG', 'OFSUC']
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search