![]() ![]() ![]() Instead, it returns the first index of the element found in the array or will return -1 (which represents that the element is not found). indexOf() to determine whether the element is present in the array. It returns the boolean value: true or false. The includes() method determines whether the element is included in the array. The Array.includes() method was introduced in ECMAScript 6. Difference between Array.includes() and Array.indexOf() If the start position is negative, the computed index is calculated as a position in an array to search for the element.Īn entire array will be searched if the computed index is less or equal to -1 * array.length. Therefore, the array will not be searched. The output of the above code is the following.įalse is returned if the start position is greater than or equal to the array’s length. Console.log(.includes(3, 2)) console.log(.includes(19, 1)) console.log(.includes(46, -1)) console.log(.includes(NaN))
0 Comments
Leave a Reply. |