0

I have a complicated response from an http request as shown below:

"rates": [
            {
                "non_refundable": false,
                "no_of_rooms": 1,
                "includes_wifi": false,
                "includes_boarding": true,
                "has_promotions": true,
                "group_code": "xgirbylkwb6xtg",
                "currency": "INR",
                "cancellation_policy": {
                    "under_cancellation": false,
                    "details": [
                        {
                            "from": "2016-12-25T00:00:00",
                            "flat_fee": 20309.01,
                            "currency": "INR"
                        }
                    ],
                    "cancel_by_date": "2016-12-24T00:00:00",
                    "amount_type": "value"
                }
           }
      ]

Rates length is between 6-20 inside another array with length of around 200. The "cancellation_policy"shows up only if "non_refundable": false.

How I can access "from": "2016-12-25T00:00:00" and change the format with Moment JS and how I can access "flat_fee": 20309.01?

I tried using angular.forEach already but it defines only the value of last array .

I tried this already:

 if ($scope.data[i].rates[j].non_refundable == false) {
for (var d = $scope.data[i].rates[j].cancellation_policy.details.length - 1; d >= 0; d--) {

But I had no success.

ps: The value should show on $mdDialog

2
  • Your question is confusing. Are you asking about how to loop in an array? Commented Oct 15, 2017 at 10:48
  • @AbhinavJain actually I would like to loop in array in object that its inside array but all I get just the last value Commented Oct 15, 2017 at 11:09

1 Answer 1

1

You don't need to loop under details, just do it like this :

var startdate = $scope.data[i].rates[j].cancellation_policy.details[0].from;
var new_date = moment(startdate).format('MMMM Do YYYY, h:mm:ss a');
var other = $scope.data[i].rates[j].cancellation_policy.details[0].flat_fee;
Sign up to request clarification or add additional context in comments.

8 Comments

I try var other = $scope.data[i].rates[j].cancellation_policy.details[0].flat_fee; but still get the last value only and in some part "details" length is 2 or 3 how I can get those value??
Did you miss something on json object?
from object I don't think so I lost way some part in my codes that I can't figure out
may be in your object you got different object under details did you got other possibility format?
all objects are from outsource http request and this is from documentation : details array List of cancellation windows and applicable charges. Refer policy details below. I try so many way now for almost 2 days
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.