Assigning Values to an Array: Difference between revisions
Content added Content deleted
(→Forth: rm) |
(rm JavaScript and LSE) |
||
Line 319: | Line 319: | ||
map.put(key,val); |
map.put(key,val); |
||
}</lang> |
}</lang> |
||
==[[JavaScript]]== |
|||
function setElem(array, loc, val) { //returns 0 if out of bounds |
|||
if(typeof array[loc] == typeof undefined) { |
|||
return 0; //element doesn't already exist -- out of bounds |
|||
} else { |
|||
array[loc] = val |
|||
return 1; //OK |
|||
}//if |
|||
}//setElem |
|||
//use: |
|||
var ary=[10,20,30] //0,1,2 defined |
|||
var ok = setElem(ary,3,'three') |
|||
if(!ok) alert('oops, error') |
|||
Simpler if you don't mind adding an element if it does not already exist: |
|||
function writeToArray(array, loc, val) { array[loc] = val; } |
|||
==[[LSE64]]== |
|||
10 array :array |
|||
0 array 5 [] ! # store 0 at the sixth cell in the array |
|||
==[[mIRC Scripting Language]]== |
==[[mIRC Scripting Language]]== |