map and filter for objects. I've done this a couple of times.
map
filter
const Obj = { map(fn, data) { let result = {}; for (let [key, value] of Object.entries(data)) { result[key] = fn(value, key, data); } return result; }, filter(fn, data) { let result = {}; for (let [key, value] of Object.entries(data)) { if(fn(value, key, data)) { result[key] = value; } } return result; } };
I've also used a "better" typeof.
typeof
function what_is(arg) { const is = Object.prototype.toString.call(arg); return { val: () => is, object: () => is == '[object Object]', array: () => is == '[object Array]', promise: () => is == '[object Promise]', undefined: () => is == '[object Undefined]', null: () => is == '[object Null]', number: () => is == '[object Number]', func: () => is == '[object Function]' }; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
map
andfilter
for objects. I've done this a couple of times.I've also used a "better"
typeof
.