underscore-es
Version:
javaScript's functional programming helper library for ES6 and beyond.
11 lines (9 loc) • 313 B
JavaScript
// `_size` : a collection's function
// ----------------------------------
import _keys from './keys';
import {isArrayLike} from './_internal';
// Return the number of elements in an object.
export default function (obj) {
if (obj == null) return 0;
return isArrayLike(obj) ? obj.length : _keys(obj).length;
}