I'm looking for a method to update arrays via closure. Is there anything that would be more efficient than this.
p.s. I'm not actually using inputs in this manner to set values. They are being passed via another function. Just needed an easy way to get my main point across.
<script>
sampleArrayValues=['copy','this','array'];
a="none";
function updateArr(val,index,action) {
var v=value;
var i=index;
var a=action;
var arr=[];
return function(v,i,a) {
if(a=="none"){
}
if(a=="copy"){
arr=sampleArrayValues;
}
if(a=="update"){
arr[index]=val;
}
return arr;
}
}
updateArr.update1 = updateArr(0,0,a);
function scoopValues(){
var val=0 || document.getElementById('one').value;
var index=0 || document.getElementById('two').value;
var action="none" || document.getElementById('three').value;
alert(updateArr.update1(val,index,action))
}
Enter value: <input id="one" style="width:20px;height:20px"/>
<br>
Enetr index: <input id="two"style="width:20px;height:20px"/>
<br>
Enter Action "none" "copy" or "update": <input id="three"style="width:60px;height:20px"/>
<br>
<input type="button" onclick="scoopValues()" value="click to update"style="width:100px;height:25px"/>