title: Sorting Object Array from another Object Array JQUERY
body: <p>i have bellow two object arrays</p>
  
  <pre><code>var array_1 = [{"Product_Name" : "p1"},{"Product_Name" : "p2"},{"Product_Name" : "p3"}]
  var array_2 = [{"Product_Name" : "p5"},{"Product_Name" : "p1"},{"Product_Name" : "p3"},{"Product_Name" : "p2"},{"Product_Name" : "p4"}]
  </code></pre>
  
  <p>as you can see my second array is not in the order as first array. im trying to order second array as same as array 1. </p>
  
  <p>i use bellow code but getting the result </p>
  
  <pre><code>function mapOrder (array, order, key) {
  
  array.sort( function (a, b) {
  var A = a[key], B = b[key];
  
  if (order.indexOf(A) == order.indexOf(B)) {
    return 1;
  } else {
    return -1;
  }
  
  });
  
  return array;
  };
  
  var item_array, item_order, ordered_array;
  item_array = array_2;
  item_order = array_1;
  ordered_array = mapOrder(item_array, item_order, 'Product_Name');
  </code></pre>
  
  <p>any suggestions get the second array as bellow</p>
  
  <pre><code>var array_2 = [{"Product_Name" : "p1"},{"Product_Name" : "p2"},{"Product_Name" : "p3"},{"Product_Name" : "p4"},{"Product_Name" : "p5"}]
  </code></pre>