function filterByType() { [type, ...arr] = arguments; return arr.filter(e => typeof e == type) } let obj = filterByType ('string', 10, 20, 'a', 'b', true, false); alert(JSON.stringify(obj));