And that is exactly the problem. The "for ... in" construct is defined as enumerating the properties of objects, not the elements of arrays.
-- Martin Cooper On Fri, Aug 23, 2013 at 4:39 AM, .//Hack <[email protected]> wrote: > if you look closely, I use array of objects. And iteration in array but > not in object. Now I use "user[action].forEach(function(act){" and don't > have problem > > 23/08/13 15:05:53, Fedor Indutny <[email protected]>: > > Sorry, but I can't see a problem here... For each iterates not only > through own properties, but through the prototype's properties too. That's > how it is defined in spec, and that's how javascript behaves. > > What you probably want to do is `Object.keys(obj).forEach(function(key) { > var value = obj[key]; ... })`. > > Cheers, > Fedor. > > > On Fri, Aug 23, 2013 at 3:04 PM, Александр Крылов <[email protected]>wrote: > >> Installed next modules: >> >> cloneextend >> express >> imagemagick >> mongodb >> mongoose >> nodemailer >> session-mongoose >> socket.io >> validator >> >> And I didn't extend prototype. With Array.forEach no problem. Only for in >> >> пятница, 23 августа 2013 г., 14:52:00 UTC+4 пользователь Fedor Indutny >> написал: >>> >>> It seems that you've installed modules that are extending Array's or >>> Object's prototype. >>> >>> Cheers, >>> Fedor. >>> >>> >>> On Fri, Aug 23, 2013 at 2:24 PM, Александр Крылов <[email protected]>wrote: >>> >>>> Hello! >>>> I have problem. >>>> >>>> For test example code: >>>> >>>> var user = {} >>>> var action = 'test'; >>>> >>>> user[action] = [{ user_id: '521319f2df3b320810000005', >>>> _id: '521723678857785c0500000b', >>>> action: { acType: 'photo', acId: '3' }, >>>> viewed: false }, >>>> { user_id: '521319f2df3b320810000005', >>>> _id: '5217293a1cab19bc11000008', >>>> action: { acType: 'photo', acId: '1' }, >>>> viewed: false }, >>>> { user_id: '521319f2df3b320810000005', >>>> _id: '52172c97d8b04bdc11000008', >>>> action: { acType: 'photo', acId: '1' }, >>>> viewed: false }, >>>> { user_id: '521319f2df3b320810000005', >>>> _id: '52172cc201feeff811000008', >>>> action: { acType: 'photo', acId: '1' }, >>>> viewed: false }, >>>> { user_id: '521319f2df3b320810000005', >>>> _id: '52172ce901feeff811000009', >>>> action: { acType: 'photo', acId: '1' }, >>>> viewed: false }, >>>> { user_id: '521319f2df3b320810000005', >>>> _id: '52172d0d80f9c07013000008', >>>> action: { acType: 'photo', acId: '1' }, >>>> viewed: false }, >>>> { user_id: '521319f2df3b320810000005', >>>> _id: '52172e038c017e0412000008', >>>> action: { acType: 'photo', acId: '1' }, >>>> viewed: false }, >>>> { user_id: '521319f2df3b320810000005', >>>> _id: '52172e8ca282584010000008', >>>> action: { acType: 'photo', acId: '1' }, >>>> viewed: false }]; >>>> console.log(user[action]); >>>> for(var i in user[action]){ >>>> console.log(i); >>>> } >>>> >>>> So, first console.log shows all elemrnts of array, good. Second >>>> console.log shows key of iteration and shows: >>>> >>>> 0 >>>> 1 >>>> 2 >>>> 3 >>>> 4 >>>> 5 >>>> 6 >>>> 7 >>>> _atomics >>>> validators >>>> _path >>>> _parent >>>> _schema >>>> _cast >>>> id >>>> toObject >>>> inspect >>>> create >>>> notify >>>> _markModified >>>> _registerAtomic >>>> $__getAtomics >>>> hasAtomics >>>> push >>>> nonAtomicPush >>>> $pop >>>> pop >>>> $shift >>>> shift >>>> pull >>>> remove >>>> splice >>>> unshift >>>> sort >>>> addToSet >>>> set >>>> indexOf >>>> >>>> I tested in Node.js (0.10.12) and all browsers. Problem only in node.js >>>> Can you help me? >>>> >>>> -- >>>> -- >>>> Job Board: http://jobs.nodejs.org/ >>>> Posting guidelines: https://github.com/joyent/**node/wiki/Mailing-List- >>>> **Posting-Guidelines<https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines> >>>> You received this message because you are subscribed to the Google >>>> Groups "nodejs" group. >>>> To post to this group, send email to [email protected] >>>> >>>> To unsubscribe from this group, send email to >>>> nodejs+un...@**googlegroups.com >>>> >>>> For more options, visit this group at >>>> http://groups.google.com/**group/nodejs?hl=en?hl=en<http://groups.google.com/group/nodejs?hl=en?hl=en> >>>> >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "nodejs" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to nodejs+un...@**googlegroups.com. >>>> >>>> For more options, visit >>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>>> . >>>> >>> >>> > -- > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
