PDA

View Full Version : Pull variable into loop and assign value



Mr J
Nov 27th, 2005, 02:57 PM
How do I define a variable in a loop and assign it the value of the relevent argument?

<script type="text/javascript">

var type,size,color

variable=new Array(type,size,color)

data=new Array()
data[data.length]=new DBO("shirt","12","red")
data[data.length]=new DBO("sweater","14","blue")
data[data.length]=new DBO("skirt","10","white")

function DBO(){
for(i=0;i<arguments.length;i++){

this.variable[i]=arguments[i]

}
}

</script>

Mr J
Nov 28th, 2005, 07:05 PM
My bump:)

Normally you assign the properties of the objects like this

function DBO(type,size.color){
this.type=type
this.size=size
this.color=color
}

I was hoping to put the variables into an array and then reference the variables ordinally as per the arguments length and assign the current value to the relevent property for that object.