 <p>You can use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort"><code>Array#sort</code></a> with <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs"><code>Math.abs()</code></a>.</p> <pre><code>arr.sort((a, b) =&gt; Math.abs(a - num) - Math.abs(b - num)); </code></pre> <p>Using ES5 Syntax for older browsers</p> <pre><code>arr.sort(function(a, b) { return Math.abs(a - num) - Math.abs(b - num); }); </code></pre> <p>To consider negative numbers too, don't use <code>Math.abs()</code>.</p> <p><div class="snippet" data-lang="js" data-hide="true" data-console="true"> <div class="snippet-code snippet-currently-hidden"> <pre class="snippet-code-js lang-js prettyprint-override"><code>var arr = [10, 45, 69, 72, 80]; var num = 73; var result = arr.sort((a, b) =&gt; Math.abs(a - num) - Math.abs(b - num));; console.log(result);</code></pre> </div> </div> </p>