It doesn't matter how gracefully es6 judges that the values contained in two arrays are exactly the same.

this is what I do now. Is there a better way?

let flag = true
    const listA = [1, 2, 3]
    const listB = [2, 3, 4]
    if (listA.length !== listB.length) {
      flag = false
    } else {
      listA.forEach(item => {
        if (listB.indexOf(item) === -1) {
          flag = false
        }
      })
    }
Mar.10,2021

it can be done in one sentence:

const checkArrSames = (arr1, arr2) => [...new Set(arr1)].length === [...new Set([...arr1, ...arr2])].length;
Menu