var hosts = ['www.google.com', 'rambler.ru', 'yandex.ru', 'www.bing.com']; hosts.sort(function(h1, h2) { h1 = h1.replace(/^www\./, ''); h2 = h2.replace(/^www\./, ''); return h1 < h2 ? -1 : h1 > h2 ? 1 : 0; }); alert(hosts.join('\n'));