JSFiddle - React, Tailwind, and code Playground

by Johan Vandeplas

JavaScript

var a = {
        "Required": {
            "Center": "radio_Required_Center_0,radio_Required_Center_1,",
            "Left": "radio_Required_Left_0,"
        }
    }
    // step 1
    console.log("step 1", a.Required);
    // step 2
    console.log("step 2", a.Required.Center, a.Required.Left);
    // step 3
    var center = a.Required.Center.split(',');
    var left = a.Required.Left.split(',');
    console.log("step 3", center, left);
    // step 4
    console.log("step 4");
    for(var i = 0; i<center.length; i++){
        console.log("doing somthing with", center[i]);
    }



/* note that the string has a trailing, an empty var will be added to the array. Strip the trailing comma with substr(0, stringlength-1) to prevent this. */
    
    var center = a.Required.Center.substr(0,a.Required.Center.length-1).split(',');
    var left = a.Required.Left.substr(0,a.Required.Left.length-1).split(',');
    console.log("stripped comma", center, left);