1

I have array of json object as following

{
    "01/15/2015_1": [
        [
            {
                "sequenceType": -1,
                "delflag": -1
            },
            {
                "sequenceType": -1,
                "delflag": -1
            }
        ]
    ],
    "01/15/2015_2": [
        [
            {
                "sequenceType": -1,
                "delflag": -1
            },
            {
                "sequenceType": -1,
                "delflag": -1
            }
        ]
    ]
}

By iterating it with jquery's each() I am getting object as following order:

1."01/15/2015_1"
2."01/15/2015_2"

But I want it in reverse() say as following:

1."01/15/2015_2"
2."01/15/2015_1"

Need help..

Is it possible with ng-repeat?

2

2 Answers 2

7

An Objekt has no defined order, so you cannot make sure this works well in every browser.

You have to grab the keys, Object.keys(), sort them and loop through it by key.

e.g.:

var obj = {
    "01/15/2015_1": [
       "example1"
    ],
    "01/15/2015_3": [
        "example3"
    ],
    "01/15/2015_2": [
        "example2"
    ]
}
var keys = Object.keys( obj ).sort();
var klen = keys.length;
for( var idx = 0; idx < klen; idx++ ){
    console.log( obj[ keys[ idx ] ] )
}
Sign up to request clarification or add additional context in comments.

Comments

0

Probably duplicate of https://stackoverflow.com/questions/5906061/can-i-make-jquerys-each-method-iterate-in-reverse:

Sulution:

$.each(array.reverse(), function() { ... });

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.