I have the following JSON object array in javascript :
[{ "AuthorName" : "Abc", "BookName" : "book-1" }]
[{ "AuthorName" : "Abc", "BookName" : "book-2" }]
[{ "AuthorName" : "Abc", "BookName" : "book-3" }]
[{ "AuthorName" : "Abc", "BookName" : "book-4" }]
Now I want to create a single JSON object from the above JSON objects array. The newly created single JSON object contains 2 properties: AuthorName and BooKName array. I am trying to achieve something like this:
{ "AuthorName" : "Abc", "Book" : ['book-1', 'book-2', 'book-3', 'book-4'] }
Now my question is, how can I achive this efficiently and with writing minimum code in javascript?
1 Answer