```Search.run().each(function(result, index)``` Ca...
# suitescript
c
Copy code
Search.run().each(function(result, index)
Can I expect the each callback to have an index available? I'm seeing it log empty.
a
no the .each function just has the result as the param, there's no sense of the order, unless you have something in the resultSet that they're sorted by or something.. but its not a for loop, its an each loop so there is no
i
c
Thanks
e
If you need the index, you could instead use
getRange()
instead of
each()
, which returns a normal
Array
so you could use
forEach((result, index) => ...
s
then again, needing the index is often an antipattern in this functional/declarative style of programming.
that said, sometimes NetSuite's obtuse APIs may require it
c
I'm using an index as a quick way of testing - I wanted to drop out of the loop early so I could print the results in a way that NS can format in the debug log
It's not needed for the solution beyond that.
b
keep track of how many times the each has run and use as your index
s
or use eric's approach and something like lodash
c
let i=0 {loop i++ print i } my quick index
s
it's common for me to use a
.take(1)
for testing, then just remove that from the chain when I want the entire search result set to run
👍 1
👍🏽 1
( or
.take(10)
etc)