{"id":1227,"date":"2023-05-21T07:07:46","date_gmt":"2023-05-21T07:07:46","guid":{"rendered":"https:\/\/itnotes.apjsoftwares.com\/?p=1227"},"modified":"2023-05-21T07:07:46","modified_gmt":"2023-05-21T07:07:46","slug":"what-are-the-important-javascript-array-method-explain-with-example","status":"publish","type":"post","link":"https:\/\/itnotes.apjsoftwares.in\/index.php\/2023\/05\/21\/what-are-the-important-javascript-array-method-explain-with-example\/","title":{"rendered":"What are the important JavaScript Array Method explain with example?"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">JavaScript Array Methods<\/h3>\n\n\n\n<p>The Array object has many properties and methods which help developers to handle arrays easily and efficiently. You can get the value of a property by specifying arrayname.property and the output of a method by specifying arrayname.method().<\/p>\n\n\n\n<ul>\n<li><strong>length property<\/strong>&nbsp;\u2013&gt; If you want to know the number of elements in an array, you can use the length property.<\/li>\n\n\n\n<li><strong>prototype property<\/strong>&nbsp;\u2013&gt; If you want to add new properties and methods, you can use the prototype property.<\/li>\n\n\n\n<li><strong>reverse method<\/strong>&nbsp;\u2013&gt; You can reverse the order of items in an array using a reverse method.<\/li>\n\n\n\n<li><strong>sort method \u2013&gt;<\/strong>&nbsp;You can sort the items in an array using sort method.<\/li>\n\n\n\n<li><strong>pop method<\/strong>&nbsp;\u2013&gt; You can remove the last item of an array using a pop method.<\/li>\n\n\n\n<li><strong>shift method<\/strong>&nbsp;\u2013&gt; You can remove the first item of an array using shift method.<\/li>\n\n\n\n<li><strong>push method<\/strong>&nbsp;\u2013&gt; You can add a value as the last item of the array.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;html&gt;\n&lt;head&gt;\n    &lt;title&gt;Arrays!!!&lt;\/title&gt;\n    &lt;script type=\"text\/javascript\"&gt;\n        var students = new Array(\"John\", \"Ann\", \"Aaron\", \"Edwin\", \"Elizabeth\");\n        Array.prototype.displayItems=function(){\n            for (i=0;i&lt;this.length;i++){\n                document.write(this[i] + \"&lt;br \/&gt;\");\n            }\n        }    \n        document.write(\"students array&lt;br \/&gt;\");\n        students.displayItems();\n        document.write(\"&lt;br \/&gt;The number of items in students array is \" + students.length + \"&lt;br \/&gt;\");\n        document.write(\"&lt;br \/&gt;The SORTED students array&lt;br \/&gt;\");\n        students.sort();\n        students.displayItems();\n        document.write(\"&lt;br \/&gt;The REVERSED students array&lt;br \/&gt;\");\n        students.reverse();\n        students.displayItems();\n        document.write(\"&lt;br \/&gt;THE students array after REMOVING the LAST item&lt;br \/&gt;\");\n        students.pop();\n        students.displayItems();\n\t\tdocument.write(\"&lt;br \/&gt;THE students array after PUSH&lt;br \/&gt;\");\n        students.push(\"New Stuff\");\n        students.displayItems();\n    &lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript Array Methods The Array object has many properties and methods which help developers to&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[23],"tags":[],"_links":{"self":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1227"}],"collection":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/comments?post=1227"}],"version-history":[{"count":1,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1227\/revisions"}],"predecessor-version":[{"id":1228,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1227\/revisions\/1228"}],"wp:attachment":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/media?parent=1227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/categories?post=1227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/tags?post=1227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}