0

This is a question that has come up a few times on here in the past but I just can't get my head around it.

This is how my output is looking at the moment:

0 "affiliate_hoover_plugin_options[1][radioName]:mac"

1 "checked:true"

2 "affiliate_hoover_plugin_options[2][radioName]:pc"

3 "checked:false"

4 "affiliate_hoover_plugin...ons[3][radioName]:linux"

5 "checked:false"

And this is how I want it to look:

1: "affiliate_hoover_plugin_options[1][radioName]:mac", "checked:true"

2: "affiliate_hoover_plugin_options[2][radioName]:pc", "checked:false"

3: "affiliate_hoover_plugin...ons[3][radioName]:linux", "checked:false"

This is how my code looks:

var newForm = [];

for (var i = 1; i < oldForm.length; i += 1) {

newForm.push(oldForm[i].name + ":" + oldForm[i].value);

if (oldForm[i].type === "radio") {
    newForm.push("checked" + ":" + oldForm[i].checked);
}

}

console.log(OnewForm);

Now I'm going to have put an extra for loop in there aren't are, which is where I'm confusing myself.

I think I just need a break

2 Answers 2

1

like this?

var newForm = [];

for (var i = 1; i < oldForm.length; i += 1) {
    if (oldForm[i].type === "radio") {
        newForm.push( [ oldForm[i].name + ":" + oldForm[i].value, "checked:" + oldForm[i].checked ] );
    } else {
        newForm.push( [ oldForm[i].name + ":" + oldForm[i].value ]);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

This was a workable solution. It wasn't quite what I was looking for but it did the job, ta
0
var newForm = [];

for (var i = 0; i < oldForm.length; i++) {
    var array = [];
    array.push(oldForm[i].name + ":" + oldForm[i].value);
    array.push("checked" + ":" + oldForm[i].checked);
    newForm.push(array);
}

console.log(newForm);

might work

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.