Sorts an array in javascript by the given property