开发者

Javascript Object literal

开发者 https://www.devze.com 2023-03-12 03:17 出处:网络
He开发者_如何学运维re is my object literal: var obj = {key1: value1}; How can I add: {key1: value1,value2,value3}

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

精彩评论

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