0

I have two arrays, e.g. : Note: Element 'total' is static and exist in arrays in every case.

let array1 = ['duck', 'bird', 'dog', 'total'] 
let array1 = ['pool', 'total', 'cat', 'run', 'kid', 'bike']

I want to use let isValid = array1.some(element => array2.includes(element)) method, but in its pure form it returns true when find first equal elements. I want to skip the static element, wich in this case is 'total'.

  • Use the linked questions' answer https://stackoverflow.com/a/39893636/2715716 but do `array.filter(item => item !== 'total')` first to remove the static element from both arrays before doing the comparison. – Tomáš Hübelbauer Feb 01 '23 at 11:18
  • or `const found = arr1.some(r => r !== 'total' && arr2.includes(r))` – mplungjan Feb 01 '23 at 11:20
  • Please visit the [help], take the [tour] to see what and [ask]. Do some research - [search SO for answers](https://www.google.com/search?q=javascript+some+but+filter+site%3Astackoverflow.com). If you get stuck, post a [mcve] of your attempt, noting input and expected output using the [\[<>\]](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Feb 01 '23 at 11:22

0 Answers0