Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript array includes another array

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"
Comment

JavaScript find elements in array that matches another array

let haveItList = ['apples', 'milk', 'bread', 'peanutbutter'];
let wishList = ['cookies', 'bread', 'jam', 'peanutbutter', 'bananas', 'cheese'];

let inBothLists = wishList.filter(element => haveItList.includes(element));
// inBothLists = ['apples', 'bread', 'peanutbutter'];
Comment

javascript check if elements of one array are in another

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

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

// 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
Comment

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

// 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
Comment

javascript check if array is subset of another

let superSet = ['B', 'C', 'A', 'D'];
let subSet = ['D', 'C'];
let mixedSet = new Set([...superSet, ...subSet]);
let isSubset = mixedSet.size == superSet.length
Comment

if array ontains any item of another array js

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

find items in array not in another array javascript

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"
Comment

PREVIOUS NEXT
Code Example
Javascript :: Using "requireCordovaModule" to load non-cordova module "xcode" is not supported 
Javascript :: remove milliseconds from datetime js 
Javascript :: check if function is async javascript 
Javascript :: number validation in javascript 
Javascript :: send multiple files using formdata jquery 
Javascript :: getkey by value js 
Javascript :: how to return 5 records instead of 10 records in datatable in laravel 
Javascript :: map with promise.all 
Javascript :: discord.js send message to specific channel 
Javascript :: javascript clone array of objects 
Javascript :: copy to clipboard react native 
Javascript :: js array sort 
Javascript :: js alphabets array 
Javascript :: open a html file using js 
Javascript :: javascript infinite loop 
Javascript :: string split javascript newline 
Javascript :: how to cut a string in js 
Javascript :: firebase storage javascript delete document 
Javascript :: ciclo for javascript 
Javascript :: how to go to next page on button click js 
Javascript :: how to wait until a variable is set javascript 
Javascript :: javascript dedupe array 
Javascript :: get element with one or another class 
Javascript :: xmlhttprequest response 
Javascript :: electron js development auto refresh 
Javascript :: simple game engine in javascript 
Javascript :: uppercase in word javascript 
Javascript :: invalid time value react datepicker 
Javascript :: in puppeteer wait for page untile certain selector have certain value 
Javascript :: javascript seconds to date 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =