What is the difference between array.splice(array.indexOf('') and array.filter(x => x !== "") in javascript?

Viewed 14

I was trying to remove empty strings ('') from an javascript array. For example: ['a','b', '', '', '', 'c', ''] ---> ['a', 'b', 'c']

So i tested two commands:

 array.splice(array.indexOf(''))

and

array.filter(x => x !== "")

both commands worked. But now i'm confused about their differences.

0 Answers
Related