Filter an object, array or string in JavaScript