How to pass a variable and not a field_name in frappe frm.set_value

Good day,

I have written a function so that if one check bok is selected then all other fields are made 0 but i have realized that frm.set_value(field_name, value) doesn’t take a available but the doc field name as it is, can someone help me as i don’t want to write many ifs

	let switch_month_periods = function(frm, selected){
		const periods = ["1_month", "6_month", "12_month", "24_month", "48_month"];
		for (let i = 0; i < periods.length; i++) {
			if(selected != "periods[i]"){
				frm.set_value(periods[i], 0)
			}else{
				frm.set_value(periods[i], 1)
			}
		}
	}

Update this line:

if (selected !== periods[i]) {

Variable periods[i] is not enclosed in quotes, so it is correctly interpreted as the value from the periods array (e.g., "1_month", "6_month"). This allows frm.set_value to properly set the value of the field corresponding to the variable’s value. so try it.