I am attempting to create a JSON object dynamically by pulling data from an array in D3 JavaScript. (The code below is not the exact one I used, but similar)
let radius = [10,20,30];
let jsonradius = '[{';
for (let i = 0; i < radius.length; i++) {
jsonradius += '"radius":';
jsonradius += 'radius[i]';
jsonradius += ',';
}
jsonradius += '}]';
By using flags, I ensure that a comma is not placed after the last entry, resulting in a perfectly formatted JSON when printed using the text(jsonradius) function.
'[{"radius":10,"radius":20,"radius":30}]'
However, when I try to access it as shown below, no value is returned.
'd3.selectAll("circle").data(jsonradius).enter().select("circle").attr("r",function(d){return d.radius;});'
I am new to D3 and JavaScript. Please guide me on how to build JSON objects dynamically.