Check Array Empty In Javascript Object Sorting