Code Like A JavaScript Pro With These Useful Js Snippets

<p>In this article I&#39;m going to be sharing with you some useful JavaScript codes/snippets to help you code faster and not be brainstorming different ways to perform simple tasks with JavaScript.</p> <p><img alt="" src="https://miro.medium.com/v2/resize:fit:630/0*OnjuxkJvyg_AKNdm" style="height:467px; width:700px" /></p> <p>Photo by Safar Safarov on Unsplash</p> <p>The first one is converting objects into an array of key value pairs. Passing an object as an argument to the object dot entries function returns an array of arrays where each inner array is a key-value pair Of each item in the object.</p> <pre> const aboutMe = { name: &#39;John&#39;, username: &#39;Cyberohn&#39; } const aboutMeArray = object.entries(aboutMe) console.log(aboutMeArray) //[[&#39;name&#39;, &#39;John&#39;], [&#39;username&#39;, &#39;Cyberohn&#39;]] </pre> <p>The next one is sorting an array. The sort method of an array sorts the elements of the array based on their Unicode value in ascending order. It also takes in a comparison function as an argument, which takes two elements A and B as inputs, and subtracts B from A. If the result of the subtraction is a negative number, then A will be sorted before B, resulting in a descending sort.</p> <p><a href="https://medium.com/@cyberohn/code-like-a-javascript-pro-with-these-useful-js-snippets-bca4a47d4ad3">Read More</a></p>