JavaScript Array.sort with examples

I was reading a social post and found that Array.sort() works great across all the browser. I thought to write small demo to show powerful compare function to sort object type array on given property.

Example: Array.sort()

Also, Array.sort() is a string sort by default! Should be used for string like type only!

array-sort array-sort-output

So, you can not use for Array.sort() for numeric sort! 🙁

But, you can use compare callback function to work with Object type Array very efficiently.

Example: Array.sort(compareFunction)

array-sort-compare-function array-sort-compare-function-output

Read: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort?redirect=no

One of the best way to check property of an Object in JavaScript

I always wonder which is the best way to check property of any Object in Javascript. Here is the example

Example 1

Example 2

Facebook JavaScript SDK with Graph API and Prototype JS

I was thinking to post from long time. I could not had time as I am busy these days because of school and work. I was reading new Facebook Graph API to solve one bug at my workplace. I could not find any straight forward example for that. So, I thought that I should post something so, it could be helpful for rookies and new bees…!!!

You can check out here. Example Page