gavinbaumanis
05/15/2023, 7:39 AMfor(myElement in myArray) {
...
}
Is there a way to determine the index?
I have dumped "myElement" and just get the type and value.
I am trying to create a condition within the loop where If the value = "0" - but only if it is the first element of the array
for(myElement in myArray) {
if(the value EQ 0 AND I myArray[0] {
}
}
I can check before the loop with arrayFirst()
But then I would need to create two loops for true/false cases.
I can change the loop, too to use index / item / to / from...
But I thought I would ask if there was someway to get the "metadata" - for interest just as much as a solution.
As always - thanks!zackster
05/15/2023, 7:46 AMSathya M
05/15/2023, 8:14 AMgavinbaumanis
05/15/2023, 8:20 AMif(local.values.first() EQ "0") {
local.p = 0;
} else {
local.p = 1;
}
for(var local.v in local.values) {
local.v = Trim(local.v);
arrayAppend(local.a, local.p & "|" & local.v);
local.p = local.p + 1;
}
I am still interested to know if there is a way to get the current index.
Eg. for a query there is currentRow()aliaspooryorik
each
. Something like this: https://trycf.com/gist/43bed6d57b6bee478d1f3282f69e5f8a/lucee5?theme=monokaialiaspooryorik
aliaspooryorik
map
https://trycf.com/gist/6cf34647b1e3a14520668adbc63d7ff3/lucee5?theme=monokaisknowlton
05/15/2023, 12:24 PMzackster
05/15/2023, 12:26 PMsknowlton
05/15/2023, 12:40 PMBill Bell
05/15/2023, 12:57 PMzackster
05/15/2023, 1:11 PMsknowlton
05/15/2023, 1:13 PMaliaspooryorik
zackster
05/15/2023, 1:23 PMaliaspooryorik
+1
inside loops 🙂sknowlton
05/15/2023, 1:27 PMsknowlton
05/15/2023, 1:27 PMsknowlton
05/15/2023, 1:28 PMaliaspooryorik
aliaspooryorik
aliaspooryorik
map
or each
.Adam Cameron
afterFirst = false
loop over the array
if afterFirst // or !afterFirst
do whatevs
/if
rest of processing
afterFirst = true
/loop
Adam Cameron
isFirst
and reverse the values, depending on what is more clear in the code, and has least negativity in its evaluation.gavinbaumanis
05/15/2023, 3:08 PMaliaspooryorik
aliaspooryorik
gavinbaumanis
05/15/2023, 4:17 PMspills
05/15/2023, 6:53 PMgavinbaumanis
05/16/2023, 12:16 AMAdam Cameron