const data = [
{ key: 'vvq', count: 999 },
{ key: 'abc', count: 99 },
{ key: 'ww', count: 1 },
{ key: 'abd', count: 100 },
{ key: 'ab', count: 10 },
{ key: 'cs', count: 100 },
{ key: 'abee', count: 999 },
{ key: 'a', count: 11 }
];
const sortData = _.sortBy(data, 'key');
const prefixMatch = str => {
const match = new RegExp(`^${str}`);
const firstMatchIndex = _.findIndex(sortData, item => match.test(item.key), 0);
let lastMatchIndex = _.findIndex(sortData, item => !match.test(item.key), firstMatchIndex);
lastMatchIndex = lastMatchIndex === -1 ? sortData.length : lastMatchIndex;
const filters = sortData.slice(firstMatchIndex, lastMatchIndex);
return _.orderBy(filters, [ 'key.length', 'count' ], [ 'asc', 'desc' ]);
};
console.log(prefixMatch('ab').map(item => item.key))
console