My array in variable is:
"1": ["48": '1', "49": '2']
"2": ["51": '3', "52": '4', "53": '5', "54": '6']
"3": ["30": '7']
I've mentioned key and value here for the 2D array, I'm trying to convert this to JSON string. I tried JSON.stringify(arraydata), arraydata is the variable where the array is stored, but it makes the string empty, whereas array data is correct.
Edit: This is how I'm adding array data:
var arraydata = new Array();
$('.classselector').each(function(){
let key1= $(this).data('key1');
let key2= $(this).data('key2');
if ( !Array.isArray(arraydata['"'+key1+'"']) ) {
arraydata['"'+key1+'"'] = new Array();
}
arraydata['"'+key1+'"']['"'+key2+'"'] = $(this).val();
});
formData["1"]["48"]="1". However, when you convert an array into a JSON string then only the numerically indexed elements will appear in the resulting string.