how to sort the object array to map with respect to fields in object array using java script
<p>I have an object array like this</p>

<pre><code>[
      {bookName:"javascript",authorName:"john"},
      {bookName:"java",authorName:"peter"},
      {bookName:"j2ee",authorName:"john"},
      {bookName:".net",authorName:"peter"},
      {bookName:"oracle",authorName:"peter"}];
</code></pre>

<p>I tried the logics but i didnt get correctly.I want to sort out like this.. </p>

<pre><code>{
peter:{
    [{bookName:"java",authorName:"peter"},

    {bookName:".net",authorName:"peter"},

    {bookName:"oracle",authorName:"peter"} ]

     } ,
john :{
    [{bookName:"j2ee",authorName:"john"},

    {bookName:"javascript",authorName:"john"}]

    }

}.
</code></pre>

<p>how can i do that.. Thanks in Advance ..</p>

<pre><code>var obj={};
var objArr = given objectarray;
for(var i=0;i&lt;objArr.length.i++ ){
  objArr[objArr[i].authorName]=objArr[i];    
}
</code></pre>

<p>and </p>

<pre><code>var obj={};
var objArr = given objectarray;
for(var i=0;i&lt;objArr.length.i++ ){
  var arr=[];
  objArr[objArr[i].authorName]=arr.push(objArr[i]);    
}
</code></pre>
