# Dynamic variable name in recordset

**URL:** <https://forum.kirupa.com/t/dynamic-variable-name-in-recordset/280925>\
**Category:** Uncategorized\
**Created:** [February 3, 2009, 1:14am UTC](https://forum.kirupa.com/t/dynamic-variable-name-in-recordset/280925 "2009-02-03T01:14:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mak\_Valley](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Mak\_Valley](https://forum.kirupa.com/u/Mak_Valley)\
**Post date:** [February 3, 2009, 1:14am UTC](https://forum.kirupa.com/t/dynamic-variable-name-in-recordset/280925/1 "2009-02-03T01:14:00Z")

</div>

```auto

	// what i have
	ans1 = pollSet.getItemAt(0).ans1;
	ans2 = pollSet.getItemAt(0).ans2;
	ans3 = pollSet.getItemAt(0).ans3;
	ans4 = pollSet.getItemAt(0).ans4;
	ans5 = pollSet.getItemAt(0).ans5;
	
	// what i want
	for (var k:Number = 0; k < numans; k++){
		var j:Number = k + 1;
		this['ans'+j] = pollSet.getItemAt(0).this['ans'+j];
	}

```

the error i get: Expected field name after ‘.’ operator

my question: How would I go about declaring a dynamic variable based on the field name like I’m attempting to? Of course I could leave it the way I have it, but for future reference, how would I harness the scope of “this”?
