开发者

Javascript Object literal

He开发者_如何学运维re is my object literal:

var obj = {key1: value1};

How can I add:

{key1: value1,value2,value3}

to the object?


var obj = {key1: [value1, value2, value3]};


If you're declaring it with the values use an array with the object literal.

var obj = {key1: [value1, value2, value3]}

If you already declared the values, still use an array, but just set the property.

obj.key1 = [value1, value2, value3]


You should modify your object at the specified key to have an array instead of a simple value:

obj.key1 = [ obj.key1, 'value2', 'value3' ];


Try

var obj = {"key": "val1"};
obj.key=[obj.key, "val2", "val3"]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜