Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create a new object element in Javascript?

I'm struggling to understand what I'm doing wrong here.

I have an empty object:

if ( doc._attachments === undefined ){
    doc._attachments = {};
}
var attmtid = 123;

which I'm trying to populate like so:

doc._attachments[attmtid].revpos = "abc";

However I keep getting an undefined error from Firebug:

doc._attachments[attmtid] is undefined

And can't really make any sense of it.

Question:
Can someone tell me what I'm doing wrong?

Thanks!

like image 958
frequent Avatar asked Jan 27 '26 03:01

frequent


1 Answers

Why not do:

doc._attachments[attmtid] = {
    revpos: "abc"
};
like image 153
Lloyd Avatar answered Jan 28 '26 17:01

Lloyd