title: AngularJS Order JSON array and inner arrays
body: <p>Hi In my Controller from Server I am getting a JSON String</p>
  
  <pre><code>$scope.unsorted=data;
  </code></pre>
  
  <p>And the data looks like</p>
  
  <pre><code>[
    {
      "configId": 116,
      "configName": "LAND_LINE",
      "configFieldses": [
        {
          "FieldId": 784,
          "FieldName": "engine.form.1",
          "values": [
            {
              "keyname": "formName",
              "value": "Account Number",
              "id": 3068
            },
            {
              "keyname": "formValuePosition",
              "value": "right",
              "id": 3069
            }
          ]
        },
        {
          "FieldId": 783,
          "FieldName": "engine.form.0",
          "values": [
            {
              "keyname": "formName",
              "value": "Amount",
              "id": 3074
            },
            {
              "keyname": "formValuePosition",
              "value": "right",
              "id": 3075
            },
            {
              "keyname": "regexGazatteer",
              "value": "Total Charges :",
              "id": 3076
            }
          ]
        },
        {
      "FieldId": 785,
          "FieldName": "engine.table2",
          "values": [
            {
              "keyname": "regexTableHeaderStart",
              "value": null,
              "id": 3079
            },
            {
              "keyname": "regexTableBodyEnd",
              "value": null,
              "id": 3080
            },
            {
              "keyname": "tableName",
              "value": "invoice",
              "id": 3078
            }
          ]
        }
      ]
    }
  ]
  </code></pre>
  
  <p>I want to sort the <code>configFieldses</code> array based on <code>FieldId</code> and also the <code>values</code> array in each <em>configFieldses</em> based on id. So the JSON should looks like</p>
  
  <pre><code>[
    {
      "configId": 116,
      "configName": "LAND_LINE",
      "configFieldses": [
        {
          "FieldId": 783,
          "FieldName": "engine.form.0",
          "values": [
            {
              "keyname": "formName",
              "value": "Amount",
              "id": 3074
            },
            {
              "keyname": "formValuePosition",
              "value": "right",
              "id": 3075
            },
            {
              "keyname": "regexGazatteer",
              "value": "Total Charges :",
              "id": 3076
            }
          ]
        },
        {
          "FieldId": 784,
          "FieldName": "engine.form.1",
          "values": [
            {
              "keyname": "formName",
              "value": "Account Number",
              "id": 3068
            },
            {
              "keyname": "formValuePosition",
              "value": "right",
              "id": 3069
            }
          ]
        },
  
        {
      "FieldId": 785,
          "FieldName": "engine.table2",
          "values": [
            {
              "keyname": "tableName",
              "value": "invoice",
              "id": 3078
            }
            {
              "keyname": "regexTableHeaderStart",
              "value": null,
              "id": 3079
            },
            {
              "keyname": "regexTableBodyEnd",
              "value": null,
              "id": 3080
            }
          ]
        }
      ]
    }
  ]
  </code></pre>
  
  <p>What I have tried is first sort the parent array and then the child arrays.</p>
  
  <pre><code>var sortedfieldses = orderByFilter($scope.unsorted.configFieldses, '+FieldId');
  </code></pre>
  
  <p>But then How to remoive the old array from unsorted config and add the new to unsorted. And also how to loop through each and then sort it?</p>
  
  <p>What is the best way?</p>