开发者

Help manipulating array into new array in Jquery

开发者 https://www.devze.com 2023-03-24 04:51 出处:网络
Hello and thank you for your time :) My first post here, but I always end up here when im researching so I figured why no开发者_如何学Ct.

Hello and thank you for your time :) My first post here, but I always end up here when im researching so I figured why no开发者_如何学Ct.

I would like to turn this:

 {"label":"112","value":"airbrush tanning,airbrush tan"};

Into this:

{"label":"112","value":"airbrush tanning"}, {"label":"112","value": "airbrush tan"}

I was thinking about using .split() to catch each comma delimited value. But passing both into a new array is escaping me for some reason. I am not sure what method will handle this so im hoping someone will be kind enough to point me in the right direction.

Thank you again for your time.


var obj =  {"label":"112","value":"airbrush tanning,airbrush tan"};

var array = $.map(obj.value.split(","), function(value) {
    return {label: obj.label, value: value};
});

console.log(array);

http://jsfiddle.net/Aj7qF/1/

Output:

[Object { label="112", value="airbrush tanning"}, Object { label="112", value="airbrush tan"}]
0

精彩评论

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