title: How to sort json objects using the order of another json
body: <p>I have a list of parks <em>(park_list)</em> that can be sorted by distance and by area.</p>
  
  <p>I already succeeded in sorting by distance using the code below:</p>
  
  <pre><code>sortList(index){
    return function(a, b){
      return (a[index] === b[index] ? 0 : (a[index] &lt; b[index] ? -1 : 1));
    }
  }
  </code></pre>
  
  <p>However, the problem with sorting by area is different from sorting by distance. I need to sort the area depending on the order of a given area list <em>(area_list)</em>.</p>
  
  <p>My <em>park_list</em> is something like this:</p>
  
  <pre><code>[
      {
          "parkName" : "park4",
          "area_id" : "4"
      },
      {
          "parkName" : "park2",
          "area_id" : "2"
      },
      {
          "parkName" : "park1",
          "area_id" : "1"
      },
      {
          "parkName" : "park3",
          "area_id" : "3"
      },
  
  ]
  </code></pre>
  
  <p>My <em>area_list</em> goes like this:</p>
  
  <pre><code>{
      "cityId": "1",
      "areaId": "1",
      "areaName": "area1"
  }, {
      "cityId": "1",
      "areaId": "2",
      "areaName": "area2"
  }, {
      "cityId": "1",
      "areaId": "3",
      "areaName": "area3"
  }, {
      "cityId": "1",
      "areaId": "4",
      "areaName": "area4"
  }
  </code></pre>
  
  <p>I need to sort my <em>park_list</em> depending on the order of the <strong>areaId</strong> in <em>area_list</em>.</p>
  
  <p>So if my <em>area_list</em> goes something like this:</p>
  
  <pre><code>{
      "cityId": "1",
      "areaId": "2",
      "areaName": "area2"
  }, {
      "cityId": "1",
      "areaId": "4",
      "areaName": "area4"
  }, {
      "cityId": "1",
      "areaId": "1",
      "areaName": "area1"
  }, {
      "cityId": "1",
      "areaId": "3",
      "areaName": "area1"
  }
  </code></pre>
  
  <p>My <em>park_list</em> should be sorted like this:</p>
  
  <pre><code>[
      {
          "parkName" : "park2",
          "area_id" : "2"
      },
      {
          "parkName" : "park4",
          "area_id" : "4"
      },
      {
          "parkName" : "park1",
          "area_id" : "1"
      },
      {
          "parkName" : "park3",
          "area_id" : "3"
      },
  
  ]
  </code></pre>
  
  <p>I am really having a hard time about this. I would really appreciate any kind of help.</p>