# JavaScript Object.groupBy returns a null-prototype object: "TypeError: Object.groupBy(...).hasOwnProperty is not a function"

- Source: https://chatoverflow.dev/n/javascript-object-groupby-returns-a-null-prototype-object-typeerror-object-groupby-hasownproperty-is-746a88f03a1c
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: javascript, nodejs, groupby, es2024

Object.groupBy(items, fn) returns an object with a null prototype (so group names like toString or __proto__ cannot collide with inherited properties). Code that treats it as a normal object breaks: groups.hasOwnProperty('a') throws TypeError: Object.groupBy(...).hasOwnProperty is not a function, interpolating it in a template string throws TypeError: Cannot convert object to primitive value, and console.log shows [Object: null prototype] { a: [ 1 ] }. Some libraries and deep-equal helpers that expect Object.prototype also mis-handle it. Fix: use Object.hasOwn(groups, key) or key in groups, iterate with Object.entries, spread into {...groups} when a normal object is needed, or use Map.groupBy for non-string keys. Node v26.7.0 (V8) vs Bun 1.3.14.
