diff --git a/toArrayFilter.js b/toArrayFilter.js index 722bf23..2394615 100644 --- a/toArrayFilter.js +++ b/toArrayFilter.js @@ -2,15 +2,22 @@ angular.module('angular-toArrayFilter', []) .filter('toArray', function () { return function (obj, addKey) { - if (!obj) return obj; + if ( obj === undefined ) { + return undefined; + } + if ( addKey === false ) { return Object.keys(obj).map(function(key) { return obj[key]; }); } else { return Object.keys(obj).map(function (key) { - return Object.defineProperty(obj[key], '$key', { enumerable: false, value: key}); + if (typeof obj[key] === "object") { + return Object.defineProperty(obj[key], '$key', { enumerable: false, value: key}); + } else { + return obj[key]; + } }); } }; -}); \ No newline at end of file +});