I need to restructure my data so that it fits in with another piece of code. I need to convert my data (which is a name,value pair) into the following structure so that that it is processed correctly. Using JQuery how would I do so?
{items: [
{value: "21", name: "Mick Jagger"},
{value: "43", name: "Johnny Storm"},
{value: "46", name: "Richard Hatch"},
{value: "54", name: "Kelly Slater"},
{value: "55", name: "Rudy Hamilton"},
{value: "79", name: "Michael Jordan"}
]};
Right now I’ve got a $.each loop which is feeding each name,value pair in but I don’t know how I’d get that exact structure.
Why use jQuery? Do it with javascript.
The following assumes your source is an object named
valueswith properties, as opposed to an array with numeric indices: