{"id":59483,"date":"2024-09-24T11:30:00","date_gmt":"2024-09-24T06:00:00","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=59483"},"modified":"2025-10-30T16:36:32","modified_gmt":"2025-10-30T11:06:32","slug":"new-array-and-object-methods-in-javascript","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/new-array-and-object-methods-in-javascript\/","title":{"rendered":"Exploring the New Array and Object Methods in JavaScript"},"content":{"rendered":"\n<p>JavaScript continues to evolve, bringing new features and methods that make it easier to work with data structures like arrays and objects.<\/p>\n\n\n\n<p>In 2025, several new array and object methods in JavaScript that have been introduced that enhance the language&#8217;s functionality and usability. <\/p>\n\n\n\n<p>In this blog, we&#8217;ll dive into these new methods and explore how they can be used to write more efficient and readable code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>List of New Array and Object Methods in JavaScript<\/strong><\/h2>\n\n\n\n<p>Let us now see some of the New Array methods in <a href=\"https:\/\/www.guvi.in\/hub\/javascript\/\" target=\"_blank\" rel=\"noreferrer noopener\">JavaScript<\/a>:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Array.prototype.groupBy<\/strong><\/h3>\n\n\n\n<p>The groupBy method groups the elements of an array based on a specified criterion. This is particularly useful for categorizing data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>const array = &#91;6.1, 4.2, 6.3];\nconst grouped = array.groupBy(Math.floor);\nconsole.log(grouped); \/\/ { '4': &#91;4.2], '6': &#91;6.1, 6.3] }<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Array.prototype.groupByToMap<\/strong><\/h3>\n\n\n\n<p>Similar to groupBy, but returns a Map instead of an object. This can be useful when you need the benefits of a Map, such as maintaining the insertion order of keys.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>const array = &#91;'one', 'two', 'three'];\nconst groupedMap = array.groupByToMap(word =&gt; word.length);\nconsole.log(groupedMap); \/\/ Map { 3 =&gt; &#91;'one', 'two'], 5 =&gt; &#91;'three'] }<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Array.prototype.toReversed<\/strong><\/h3>\n\n\n\n<p>This method returns a new array with the elements reversed, without modifying the original array. It&#8217;s a non-destructive alternative to Array.prototype.reverse.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>const array = &#91;1, 2, 3];\nconst reversed = array.toReversed();\nconsole.log(reversed); \/\/ &#91;3, 2, 1]\nconsole.log(array); \/\/ &#91;1, 2, 3]<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Array.prototype.toSorted<\/strong><\/h3>\n\n\n\n<p>Returns a new array with the elements sorted, without modifying the original array. This is a non-destructive alternative to Array.prototype.sort.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>const array = &#91;3, 1, 2];\nconst sorted = array.toSorted();\nconsole.log(sorted); \/\/ &#91;1, 2, 3]\nconsole.log(array); \/\/ &#91;3, 1, 2]<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Array.prototype.toSpliced<\/strong><\/h3>\n\n\n\n<p>Returns a new array with some elements removed or replaced, without modifying the original array. This is a non-destructive alternative to Array.prototype.splice.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>const array = &#91;1, 2, 3, 4];\nconst spliced = array.toSpliced(1, 2, 5, 6);\nconsole.log(spliced); \/\/ &#91;1, 5, 6, 4]\nconsole.log(array); \/\/ &#91;1, 2, 3, 4]<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Array.prototype.with<\/strong><\/h3>\n\n\n\n<p>Returns a new array with a specific element replaced at a given index, without modifying the original array.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>const array = &#91;1, 2, 3];\nconst newArray = array.with(1, 4);\nconsole.log(newArray); \/\/ &#91;1, 4, 3]\nconsole.log(array); \/\/ &#91;1, 2, 3]<\/strong><\/code><\/pre>\n\n\n\n<p>These new array methods help developers reduce a lot of time while working on large set programs. Similarly, here is a list of New Object Methods:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Object.groupBy<\/strong><\/h3>\n\n\n\n<p>This method groups the values of an object based on a specified criterion and returns a new object.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>const obj = { a: 1, b: 2, c: 3 };\nconst grouped = Object.groupBy(obj, x =&gt; x % 2);\nconsole.log(grouped); \/\/ { '0': &#91;2], '1': &#91;1, 3] }<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Object.groupByToMap<\/strong><\/h3>\n\n\n\n<p>Similar to Object.groupBy, but returns a Map instead of an object. This method combines the flexibility of grouping with the advantages of a Map.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>const obj = { a: 'one', b: 'two', c: 'three' };\nconst groupedMap = Object.groupByToMap(obj, word =&gt; word.length);\nconsole.log(groupedMap); \/\/ Map { 3 =&gt; &#91;'one', 'two'], 5 =&gt; &#91;'three'] }<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Object.hasOwn<\/strong><\/h3>\n\n\n\n<p>A more concise and intuitive method to check if an object has a specific property, similar to Object.prototype.hasOwnProperty.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>const obj = { a: 1 };\nconsole.log(Object.hasOwn(obj, 'a')); \/\/ true\nconsole.log(Object.hasOwn(obj, 'b')); \/\/ false<\/strong><\/code><\/pre>\n\n\n\n<p>That&#8217;s it for new object methods. These new arrays and object <a href=\"https:\/\/www.guvi.in\/blog\/objects-methods-and-classes-in-javascript\/\" target=\"_blank\" rel=\"noreferrer noopener\">methods in JavaScript<\/a> allow you to perform complex tasks much more easily and ease your workflow!<\/p>\n\n\n\n<p>In case, you want to learn more about Javascript and other frameworks, consider enrolling for HCL GUVI&#8217;s Certified <a href=\"https:\/\/www.guvi.in\/zen-class\/java-full-stack-development-course\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=new-array-and-object-methods-in-javascript\" target=\"_blank\" rel=\"noreferrer noopener\">Java Full-stack Developer Course<\/a> that teaches you everything from scratch and make sure you master it!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>In conclusion, the new array and object methods introduced will significantly enhance JavaScript&#8217;s functionality, allowing developers to write more efficient, readable, and non-destructive code. <\/p>\n\n\n\n<p>These methods, such as <code>groupBy<\/code>, <code>toReversed<\/code>, and <code>Object.hasOwn<\/code>, simplify common operations like grouping, sorting, and checking properties, making it easier to manage and manipulate data. <\/p>\n\n\n\n<p>By incorporating these tools into your development practices, you can streamline your code and improve overall productivity.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript continues to evolve, bringing new features and methods that make it easier to work with data structures like arrays and objects. In 2025, several new array and object methods in JavaScript that have been introduced that enhance the language&#8217;s functionality and usability. In this blog, we&#8217;ll dive into these new methods and explore how [&hellip;]<\/p>\n","protected":false},"author":49,"featured_media":64339,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[294,737],"tags":[],"views":"5380","authorinfo":{"name":"Thirupathi","url":"https:\/\/www.guvi.in\/blog\/author\/thirupathi\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2024\/09\/exploring_the_new_array_and_object_methods_in_javascript_1x-300x116.webp","jetpack_featured_media_url":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2024\/09\/exploring_the_new_array_and_object_methods_in_javascript_1x.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/59483"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/49"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=59483"}],"version-history":[{"count":10,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/59483\/revisions"}],"predecessor-version":[{"id":92010,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/59483\/revisions\/92010"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/64339"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=59483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=59483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=59483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}