I am reading checkbox name and value. If there are two checkboxes if part gets executed, if single checkboox then else block will get execute.
if (Array.isArray(b.name)) {
b.options = b.name.map(function(v, i) {
return [v, b.value[i]];
});
} else {
b.options = b.name.map(function(v, i) {
return [v, b.value[i]];
});
}
In the above code if block will get executed only when there are multiple value and it works fine because we have an Array.
name = Spine and value = Spine Value
But in below scenario:
Here else part will get execute from the above snippet. But here it is returning an error saying that b.name.map is not a function.
How do I convert this string into an array similar to if block.
Tried approached so far in else block:
b.options = $.each(function(v, i) {
return [b.name, b.value];
});
$.each({name: b.name, value: b.value}, function(k, v) {
b.options = (k + "" + v);
});


Stringdoesn't have.map()method. You need to handleelsesection ofifblock. Better See: How to create a Minimal, Complete, and Verifiable example.