javascript - push and length array operation, iterating through an array -
i have following code snippets in javascript
myarr = []; myarr.push(3); myarr.push(5); myarr.push(11); // console.log(myarr.length) le = myarr.length; (var i=0; < le; i++) { elem = myarr[i]; // ... e.g. console.log(elem)
}
how translation livecode like? or put in other words - how emulate push element array operation , ask the length of array?
note: livecode seems support associative arrays , have not found "cheat sheet" yet of implemented array operations.
comment on answers
the first answer given mark. gives general idea how it. alex made code work. thank both.
the solution mark not quite correct; can't use 'push' handler name, because 'push' reserved word in livecode; in code below, i've changed use "mypush"
also, version won't work correctly, because put declaration of 'myarray' inside 'mouseup' handler - makes global array accessible within handler only. further on, when access 'myarray' within 'push' handler, declaring local, implicitly declared variable.
here's version of code changed account both problems, (appear) work properly.
global myarray on mouseup mypush 3 mypush 5 mypush 7 repeat each key mykey in myarray put myarray[mykey] & cr after msg end repeat end mouseup on mypush elem local mymaxkey put item 2 of extents of myarray mymaxkey put elem myarray[mymaxkey+1] end mypush
Comments
Post a Comment