How can I fix this code to get all prime numbers within a range?

So I am testing my algorithm and trying to print all prime numbers within a range. I think the code is logical but it keeps printing the wrong output i.e the unfiltered list of numbers.

function sumPrimes(num) {
  // Check all numbers for primality
  let a = []
  let b = []
  for (let i = 2; i <= num; i++) {
      a.push(i)
      b.push(i)
  }
  //console.log(a)
  return a.filter(function(item) {
    for(let j = 0; j < b.length; j++) {
      if(item !== b[j] && item % b[j] != 0) {
        return true
      } 
    }
    return false; 
  })
}
sumPrimes(977);