2

Hello and thank you for your time :) My first post here, but I always end up here when im researching so I figured why not.

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.

1 Answer 1

6
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"}]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.