[jQuery] Re: How to add an element to an object?

2009-07-14 Thread RobG



On Jul 15, 3:25 am, yasmine  wrote:
> Thanks, I didn't know about the javascript associative arrays.

Because javascript doesn't have them, it has objects that are simple
name/value pairs.

--
Rob


[jQuery] Re: How to add an element to an object?

2009-07-14 Thread yasmine

Thanks, I didn't know about the javascript associative arrays.


[jQuery] Re: How to add an element to an object?

2009-07-14 Thread MorningZ

Your code and what you are trying to do has nothing to do with jQuery
really.. it's all simple JS object stuff (http://www.google.com/search?
q=javascript+associative+array), with that pointed out

var d = {"one": 1, "two": 2, "three": 3};
d["four"] = 4;

would result in d being:
{ "one": 1, "two": 2, "three": 3, "four": 4 }



On Jul 14, 11:53 am, yasmine  wrote:
> Hi, am very new to jquery and I want to do something that I suppose is
> very easy but I can't figure out how to do it
> If I have something like this:
> var d = {one:1, two:2, three:3};
>
> and I want to add a new item to d, how can I do it?
>
> I have looked up the documentation and found the function called data
> (name, value) and I tried doing this
> $(d).data("four",4); but it wasn't added
>
> Thanks in advance