How to push an entry of a query result to the top?

Hi developers,

Is there any way that can push an entry to the top of the query results? For example, you want your employees to be able to query the employees database, but to push their profiles to the top, so they see their profile as the first result.

.pop and .shift only removes the last and first elements in an array, and I can figure out the index of the element by mapping ( .map ) the array for it’s keys and values, and then remove the item, and reinsert it on the beginning of the array using .unshift , that’s an approach, but how am I going to remove it from the array? Is there any method that I can call on an array to remove an item based on its index?

If there’s any other ideas or approaches please let me know, I appreciate it.

You can use sort.

Example code:

var data = [{name: 'John'},{name: 'Jacob'},{name: 'Faith'},];

$w.onReady(function () {
   var first = "Faith";
   var array = data.sort( function (x,y) {
      return x.name === first ? -1 : y.name === first ? 1 : 0;
   });
   console.log(array); //new array
});