Find the OR and AND of Array elements using JavaScript Last Updated : 11 Jul, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an array and the is task to find the OR and AND operations of the values of an Array using JavaScript. These are the following methods: Using simple for loopUsing reduce() MethodApproach 1: Using simple for loop It uses a simple method to access the array elements by an index number and use the loop to find the OR and AND of values of an Array using JavaScript. Example 1: This example uses a simple method to find the OR of Array elements using JavaScript. JavaScript function OR(input) { if (toString.call(input) !== "[object Array]") return false; let total = Number(input[0]); for (let i = 1; i < input.length; i++) { if (isNaN(input[i])) { continue; } total |= Number(input[i]); } return total; } console.log(OR([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])); Output15 Example 2: This example uses a simple method to find the AND of Array elements using JavaScript. JavaScript function AND(input) { if (toString.call(input) !== "[object Array]") return false; let total = Number(input[0]); for (let i = 1; i < input.length; i++) { if (isNaN(input[i])) { continue; } total &= Number(input[i]); } return total; } console.log(AND([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])); Output0Approach 2: Using reduce() method The array reduce() method in JavaScript is used to reduce the array to a single value and executes a provided function for each value of the array (from left-to-right) and the return value of the function is stored in an accumulator. Syntax: array.reduce( function( total, currentValue, currentIndex, arr ), initialValue ) Example 1: This example uses the array reduce() method to find the OR of values of an Array using JavaScript. JavaScript let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; function ORofArray(OR, num) { return OR | num; } console.log(arr.reduce(ORofArray)); Output15 Example 2: This example uses the array reduce() method to find the AND of values of an Array using JavaScript. JavaScript let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; function ANDofArray(AND, num) { return AND & num; } console.log(arr.reduce(ANDofArray)); Output0 Comment More infoAdvertise with us Next Article Find Common Elements In Three Sorted Arrays using JavaScript S SHUBHAMSINGH10 Follow Improve Article Tags : JavaScript Web Technologies javascript-array JavaScript-DSA JavaScript-Misc +1 More Similar Reads Find Common Elements In Three Sorted Arrays using JavaScript JavaScript can be used to find the common elements in given three sorted arrays. We are given three different sorted arrays, we have to return common elements of three arrays. Example:Input array1 = [1 , 2 , 3 , 4 ,5 ] array2 = [3 , 4, 5 , 6 ,7 ]array3 = [ 3 , 4 , 7 , 8 , 9] Output [3 , 4]Below are 4 min read JavaScript - Find All The Combinations of Array Values Combinations refer to subsets of a given array, where the order of elements does not matter. For example, given an array [1, 2, 3], the possible combinations include:Single-element combinations: [1], [2], [3]Two-element combinations: [1, 2], [1, 3], [2, 3]All three elements: [1, 2, 3]Â Here are the d 2 min read Find the Common Elements of More than Two JavaScript Arrays? Given an HTML document having multiple arrays with some elements and the task is to get the common elements from arrays with the help of JavaScript. Below are the approaches to find the common elements of more than two JavaScript Arrays:Table of ContentUsing filter methodUsing reduce method Approach 3 min read How to Create an Array using Intersection of two Arrays in JavaScript ? In this article, we will try to understand how to create an array using the intersection values of two arrays in JavaScript using some coding examples. For Example: arr1 = [1, 3, 5, 7, 9, 10, 14, 15]arr2 = [1, 2, 3, 7, 10, 11, 13, 14]result_arr = [1, 3, 7, 10, 14]Approach 1: We will see the native a 3 min read How to find every element that exists in any of two given arrays once using JavaScript ? In this article, we will learn how to find every element that exists in any of the given two arrays. To find every element that exists in any of two given arrays, you can merge the arrays and remove any duplicate elements. Table of Content Using SetUsing loopUsing filter() and concat()Using reduce a 3 min read How to get the elements of one array which are not present in another array using JavaScript? The task is to get the elements of one array that are not present in another array. Here we are going to use JavaScript to achieve the goal. Here are a few techniques discussed. Approach Take the arrays in variables.Use the .filter() method on the first array and check if the elements of the first a 2 min read Like