I have got three similar json objects. Now i wish to join the entire list and then sort the complete list according to one of the index. Here, goes the objects description
Object 1
[{"link":"#","prod":"Fundamentals Of Software Engineering","price":" Rs. 200 "},{"link":"##","prod":"Real-Time Systems: Theory And Practice","price":" Rs. 394 "}]
Object 2
[{"link":"#","prod":"Fundamentals Of Software Engineering","price":" Rs. 200 "},{"link":"##","prod":"Real-Time Systems: Theory And Practice","price":" Rs. 394 "}]
Object 3
[{"link":"#","prod":"Fundamentals Of Software Engineering","price":" Rs. 200 "},{"link":"##","prod":"Real-Time Systems: Theory And Practice","price":" Rs. 394 "}]
Once, I join all of them , I wish to sort the complete array (new one) w.r.t to price index.
Any hint for this will be appreciated.
thanks 🙂
if Object1 , Object2 and Object3 are JSON strings convert it to Javascript objects using
evalfunction.Then merge them using
concatmethod.http://www.w3schools.com/jsref/jsref_concat_array.asp
Then sort using
sortmethod in Javascript Array.ref : http://www.w3schools.com/jsref/jsref_sort.asp
ref: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort
Use
return priceB - priceA;for descending order.jsfiddle : http://jsfiddle.net/diode/FzzHz/
.