✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Change trace name plotly js

I want to assign trace names programmatically in a JS script. I have this code:

var xval = [];
for(var i=0; i < long_data2.length; i++){
          xval.push(long_data2[i]['year']);
       }

var yval = [];
for(var i=0; i < long_data2.length; i++){
          yval.push(long_data2[i]['netmig']);
       }

var ctyname = [];
for( var i = 0; i < long_data2.length; i++) {
	ctyname.push(long_data2[i]['county']);
    }


//Generating Chart  
  var trace1 = {
        "type": 'bar',
        "x": xval,
        "y": yval,
		"name" : ctyname.toString,
		"text" : ctyname,
     };

var data = [trace1];

var layout = {
    title: titStr,
    showlegend: true
};

Plotly.newPlot('chart', data, layout, {displayModeBar: true});

I want the trace name to reflect the value of “ctyname” (which changes based on user input). The trace name is always “trace 0”. I can reset it manually, but I need to be able to set it as user input changes.
How do I do this?
TIA