Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have 10 records and i have create a array then how i will get 9th record from aaray by using sorting
Posted
Updated 19-Mar-15 8:48am
v2

Just use the indexer to get the 9th element,

JavaScript
// return the 9th element of the array
var el = arr[8];


Arrays are 0-based, so 8 would return the element at 9th index. For sorting, you can call the .sort() function of the object; for more please refer MDN[^]. You should also read the quotation about the description of the procedure:

Quote:
Elements are sorted by converting them to strings and comparing strings in Unicode code point order. For example, "Cherry" comes before "banana". In a numeric sort, 9 comes before 80, but because numbers are converted to strings, "80" comes before "9" in Unicode order.


Hopefully, you will get the idea for how to doing this from MDN.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900