0

I have two arrays, one full of links and another one of domains of which shall be removed from the first array.

array1 = [ http://www.linkone.com, https://www.linktwo.com, ... ]
array2 = [ 'linkone' ]

The second array does not have the format of a URL, I've done this by doing the following:

for (let a2 of array2) {
  clearedUrls.push(_.pull(array1, `https?:\/\/www.${a2}.*`))
}

It worked, but the output of clearedUrls contains array inside of array:

[
  'https://www.foo.com',
  'https://www.foo.com',
  'https://www.foo.com',
  'https://www.foo.com',
  [
    'https://www.foo.com',
    'https://www.foo.com',
    'https://www.foo.com',
  ],
  [ ... ]
]

I know it's because every iteration it will push. I'd like to know a better way to loop over the array2, remove the URLs from array, and return the array with only links inside, no more arrays.

1 Answer 1

2

You should use concat instead of push:

clearedUrls = clearedUrls.concat(_.pull(array1, `https?:\/\/www.${a2}.*`))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.