20 javascript Array Methods
Published: 2020-06-02 03:47:32

<!-- wp:paragraph -->
<p>In this tutorial, you will learn JavaScript Array Methods including examples.  </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Sometimes, when you work with <a href="https://www.tutsmake.com/javascript-arrays/">Javascript arrays</a>, these methods help manipulate javascript array easily.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>JavaScript Array Methods</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The following array methods in javascript:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Array pop() Method</li><li>Array push() Method</li><li>Array toString() Method</li><li>Array join() Method</li><li>Array splice() Method</li><li>Array sort() Method</li><li>Array shift() Method</li><li>Array unshift() Method</li><li>Array reverse() Method</li><li>Array concat() Method</li><li>Array slice()  Method</li><li>Array filter() Method</li><li>Array find() Method</li><li>Array forEach() Method</li><li>Array map() Method</li><li>Array reduce() Method</li><li>Array some() Method</li><li>Array every() Method</li><li>FindIndex() Array Method</li><li>Array Include() Method</li><li>IndexOf() Array Method</li><li>Array lastIndexOf() Method</li><li>JavaScript Array isArray() Method</li></ul>
<!-- /wp:list -->

<!-- wp:heading {"level":3} -->
<h3>1: Array pop() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The javascript <a href="https://www.tutsmake.com/shift-unshift-push-pop-array-methods-in-javascript/#pop">pop() method</a> is used to remove the last element from an array.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The method returns the value of the removed item.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-    </h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code"> var lang = ["PHP", "Python", "Java", "C"];
 lang.pop();     </pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p>Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Output<br> // New array:  PHP, Python, Java</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>2: Array push() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The<a href="https://www.tutsmake.com/shift-unshift-push-pop-array-methods-in-javascript/#push"> js push()</a> method is used to add a new element to the end from an array.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code"> var lang = ["PHP", "Python", "Java", "C"];
 lang.push("JavaScript");         </pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Output<br>
// New array:  PHP, Python, Java, C, JavaScript</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>3: Array toString() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The <a href="https://www.tutsmake.com/javascript-array-to-comma-separated-string/#tostring">js toString()</a> method is used to convert array to string.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code"> var lang = ["PHP", "Python", "Java", "C"];
 lang.toString();</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is: </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">// output<br>
PHP, Python, Java, C</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>4: Array join() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The javascript<a href="https://www.tutsmake.com/javascript-array-to-comma-separated-string/#join"> join() method</a> is used to join the elements of an array into a string.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In otherwords, The "join()" method puts all the elements of the array into a string list. This method difference from "toString()" method.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code"> var lang = ["PHP", "Python", "Java", "C"];
 lang.join(" - ");</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p>Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">// output<br>
PHP - Python - Java - C</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>5: Array splice() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The javascript <a href="https://www.tutsmake.com/javascript-array-splice-method-by-example/">splice() method</a> is used to add and remove items from an array. </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">syntax<br>================<br>array.splice(index, howMany, [element1][, …, elementN]);</pre>
<!-- /wp:preformatted -->

<!-- wp:list -->
<ul><li> index − Index param specifies where a new item should be inserted.</li><li> howMany − An integer indicating the number of old array elements to remove. </li><li> If howMany set to 0, no items will be removed in array list.</li></ul>
<!-- /wp:list -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code"> var lang = ["PHP", "Python", "Java", "C"];
 lang.splice(2, 0, "Javascript", "Rust"); </pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p>Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">// Output<br>
new array: PHP, Python, Javascript, Rust, Java, C</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>6: Array sort() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The javascript <a href="https://www.tutsmake.com/sorting-using-javascript-array-sort-method/">array sort()</a> method either alphabetic or numeric sorts an array.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-            </h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code"> var lang = ["PHP", "Python", "Java", "C"];
 lang.sort();</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">// Outuput<br>
array: C, Java, PHP, Python</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>7: Array shift() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The javascript <a href="https://www.tutsmake.com/shift-unshift-push-pop-array-methods-in-javascript/#shift">shift() method</a> is used to remove the first element from an array. </p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-        </h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code"> var lang = ["PHP", "Python", "Java", "C"]; 
 lang.shift(); </pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">// Output<br>
new array: Python, Java, C</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>8: Array unshift() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The <a href="https://www.tutsmake.com/shift-unshift-push-pop-array-methods-in-javascript/#unshift">js unshift()</a> method adds a new element to the beginning of an array.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code"> var lang = ["PHP", "Python", "Java", "C"]; 
 cars.unshift("JavaScript");     </pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p>Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">//Output <br>
New array: JavaScript, PHP, Python, Java, C</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>9: Array reverse() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The method is used for reverses the order of the elements in an array.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code"> var lang = ["PHP", "Python", "Java", "C"];             
 lang.reverse();   </pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">// Outuput<br>
array: C, Java, PHP, Python</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>10: Array concat() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The javascript <a href="https://www.tutsmake.com/merge-two-array-javascript-concat-method/">concat() method</a> joins two or more arrays and makes a new one.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code"> var lang = ["PHP", "Python", "Java", "C"];  
 var newlang = ["JavaScript", "Rust"];  
 var join = lang.concat(newlang);    </pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">// Output<br>New array: PHP, Python, Java, C, JavaScript, Rust</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>11: Array slice() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The js <a href="https://www.tutsmake.com/javascript-array-slice/">slice() array()</a> method is used to selected elements in an array and make a new one. It can take one or two arguments.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code"> var lang = ["PHP", "Python", "Java", "C", "JavaScript"];
 var lang = cars.slice(1, 4);  </pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">//Output <br>
New Array : Python, JavaScript</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>12: Array filter() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The<a href="https://www.tutsmake.com/javascript-filter-array/"> js filter()</a> method is used to filter the array, according our conditions.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code">&lt;p>function isCheck(value) {&lt;br>
  return value &lt; 10;&lt;br>
}

var filter = [10, 5, 16, 4, 7, 12].filter(isCheck);</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p>Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Output<br> //new array: 5,4,7</pre>
<!-- /wp:preformatted -->

<!-- wp:paragraph -->
<p>In this example the function filter() creates a new array. Those elements that satisfy the condition checked by isCheck() function.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>13: Array find() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The <a href="https://www.tutsmake.com/javascript-array-find/">js find()</a> method is used find the first element of an array.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code">function isCheck(value) {
  return value >= 10;
}

var find= [10, 5, 16, 4, 7, 12].find(isCheck);</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Output<br>
// 12</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>14: Array forEach() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The JavaScript <a href="https://www.tutsmake.com/learn-javascript-foreach-method/">Array forEach</a> method permits the call of a function on each element of an array in an easy way. </p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code"> var num = [18, 12, 10, 15];
 num.forEach(function(item) {
    document.writeln(item);
 });</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Output<br> // return <br><br>18 12 10 15</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>15: Array&nbsp;map()&nbsp;Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The<a href="https://www.tutsmake.com/javascript-array-map/"> js map()</a> method, creates an array by calling a specific function on each element in the original array.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code">var numbers = [4, 9, 16, 25];
var x = numbers.map(Math.sqrt);
document.write(x);</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted"> Output
 // return   
 2,3,4,5 </pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>16: Array reduce() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The&nbsp;javascript <a href="https://www.tutsmake.com/javascript-array-reduce/">array reduce()</a>&nbsp;method reduces the array to a single value.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code">var numArr = [
        {  name: 'a', num: 50},
        {  name: 'b', num: 50},
        {  name: 'c', num: 75},
        {  name: 'd', num: 35},
        {  name: 'e', num: 25 },
        {  name: 'f', num: 40 },
    ];

    var sum = numArr.reduce(function (total, currentValue) {
        return total + currentValue.num;
    }, 0);

    document.write( "javascript- Sum of the array value is :- " + sum );</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is: </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Output
 // return   
 275</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>17: Array some() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The javascript <a href="https://www.tutsmake.com/javascript-array-some/">array some()</a> method checks whether at least one element of the array matches the given predicate. if none of the array elements match the predicate, then it will return false</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code">var nums = [3, 18, 19, 20, 25];

function checkNumber(num) {
  return num >= 25;
}

document.write(nums.some(checkNumber));</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is: </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Output
 // return   
 True</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>18: Array every() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The javascript <a href="https://www.tutsmake.com/javascript-array-every/">array every()</a> method checks whether all elements of the array match the predicate:</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Ex:-</h4>
<!-- /wp:heading -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code">var nums = [3, 18, 19, 20, 25];

function checkNumber(num) {
  return num >= 3;
}

document.write(nums.every(checkNumber));</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted"> // return   
 true</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>19: findIndex() Array Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The javascript <a href="https://www.tutsmake.com/javascript-array-findindex/"><code>findIndex()</code>&nbsp;method</a> is used to find first occurrence position from an array.</p>
<!-- /wp:paragraph -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code">let numbers = [1, 2, 3, 4, 5];
 
let res = numbers.findIndex(e => e % 2 == 1);

document.write(res); //</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted"> // return   
 0</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>20: Array include() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The <a href="https://www.tutsmake.com/javascript-array-contains/">js&nbsp;<code>includes()</code>&nbsp;</a>method returns&nbsp;<code>true</code>&nbsp;if an javascript array contains a given element; Otherwise, it returns&nbsp;<code>false</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code">[1,2,3].includes(2); // true
[1,2,3].includes(4); // false
[1,2,3].includes(1,1); // false</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted"> // return   
 true
 false
 false</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>21: indexOf() Array Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The&nbsp;js array <a href="https://www.tutsmake.com/javascript-array-indexof-lastindexof/#indexof"><code>indexOf()</code>&nbsp;method</a> is used to find the first occurrence position of an&nbsp;array And returns the index of the first occurrence of the element. If&nbsp;the element is not found, -1 return.</p>
<!-- /wp:paragraph -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code">var arr = [10, 20, 30, 40, 50, 70, 10, 50];
document.write(arr.indexOf(10)); // 0
document.write(arr.indexOf(10)); // 4
document.write(arr.indexOf(10)); // 5</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted"> // return   
0
4
5</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>22: Array lastIndexOf() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>This is similar to the indexOf() method, but one difference in these. The Javascript array <a href="https://www.tutsmake.com/javascript-array-indexof-lastindexof/#lastindexof">lastIndexOf() method</a> is used to find the last occurrence position of an array. It returns -1 if it cannot find the element.</p>
<!-- /wp:paragraph -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code">var arr = [10, 20, 30, 40, 50, 70, 10, 40];
document.write(arr.lastIndexOf(10)); // 6
document.write(arr.lastIndexOf(40)); // 7</pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p> Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted"> // return   
6
7</pre>
<!-- /wp:preformatted -->

<!-- wp:heading {"level":3} -->
<h3>23: JavaScript Array isArray() Method</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The&nbsp;javascript array <a href="https://www.tutsmake.com/javascript-check-the-object-isarray-function/"><strong>isArray</strong>() method</a> is used to check whether an <a href="https://www.tutsmake.com/javascript-objects/">object</a> is an&nbsp;<strong>array</strong>. This function returns true if the object is an&nbsp;<strong>array</strong>, otherwise return false.</p>
<!-- /wp:paragraph -->

<!-- wp:syntaxhighlighter/code {"language":"jscript"} -->
<pre class="wp-block-syntaxhighlighter-code">var arr = [5, 3, 10, 1, 6, 12]

document.write("Retrun value = " + Array.isArray(arr)); </pre>
<!-- /wp:syntaxhighlighter/code -->

<!-- wp:paragraph -->
<p>Result of the above example is:  </p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">Retrun value = true  </pre>
<!-- /wp:preformatted -->