Check If An Array Contains Any Element Of Another Array

[Solved] Check If An Array Contains Any Element Of Another Array | Solidity - Code Explorer | yomemimo.com
Question : javascript array includes another array

Answered by : sagor-mahtab

const array1= ["cheese", "dough", "sauce", "pepperoni"]
const array2= ["mozzarella", "peppers", "chicken", "cheese"]
const isIncluded = array1.some(value => array2.includes(value))
// true
const values = array1.filter(value => array2.includes(value))
// "cheese"

Source : https://dev.to/chrisdixon161/javascript-check-an-array-value-is-included-in-another-array-1hk0 | Last Update : Wed, 16 Jun 21

Question : javascript check if elements of one array are in another

Answered by : easy-earthworm

const found = arr1.some(r=> arr2.includes(r))

Source : https://stackoverflow.com/questions/16312528/check-if-an-array-contains-any-element-of-another-array-in-javascript/29447130 | Last Update : Thu, 02 Apr 20

Question : How to check if array includes a value from another array in JavaScript

Answered by : chetan-nada

// How to check if array includes a value from another array in JavaScript
const includesAny = (arr, values) => values.some(v => arr.includes(v));
includesAny([1, 2, 3, 4], [2, 9]); // true
includesAny([1, 2, 3, 4], [8, 9]); // false

Source : https://www.30secondsofcode.org/js/s/includes-any | Last Update : Sun, 09 Jan 22

Question : how to check all elements in array includes in another array javascript

Answered by : chetan-nada

// how to check all elements in array includes in another array javascript
const includesAll = (arr, values) => values.every(v => arr.includes(v));
includesAll([1, 2, 3, 4], [1, 4]); // true
includesAll([1, 2, 3, 4], [1, 5]); // false

Source : https://www.30secondsofcode.org/js/s/includes-all | Last Update : Mon, 10 Jan 22

Question : find items in array not in another array javascript

Answered by : tame-tapir-yb2xlgmhx8lv

var arr1 = [ { "prop1": "value1", "prop2": "value2", }, { "prop1": "value3", "prop2": "value4", }, { "prop1": "value5", "prop2": "value6", }, ];
var arr2 = ['value1','value3', 'newValue'];
// finds all the elements of arr2 that are not in arr1
arr2.filter( val => !arr1.find( arr1Obj => arr1Obj.prop1 === val)
); // outputs "newValue"

Source : https://stackoverflow.com/questions/2963281/javascript-algorithm-to-find-elements-in-array-that-are-not-in-another-array | Last Update : Mon, 18 Jul 22

Question : if array ontains any item of another array js

Answered by : bishoy-nasr

const found = arr1.some(r=> arr2.indexOf(r) >= 0)

Source : https://stackoverflow.com/questions/16312528/check-if-an-array-contains-any-element-of-another-array-in-javascript | Last Update : Mon, 08 Mar 21

Answers related to check if an array contains any element of another array in javascript

Code Explorer Popular Question For Solidity