im having an issue or i am missing somehting ``` ...
# suitescript
s
im having an issue or i am missing somehting
Copy code
var number = parseInt(shipmethod);
   ship = shipmettype[number]
s
There's literally nothing to go on in this screenshot. No idea what
shipmethod
,
ship
, or
shipmettype
is
s
shipmethod == internal id shipmettype== array of info ship == the result
b
it is really weird to use an internal id as an index to an array
s
Well if shipmethod is the internal id of something, and
shipmettype
is an array, what does the id have to do with the index in the array.
I don't even understand the idea of what you are doing, why would you want to subtract anything from an internalid, sounds like a really bad design.
s
the user is choosing from a dropdown list and this method var shipmethod = rec.getValue({ fieldId: "custbody55" }); gives me the internal id of the the items in the list
so the items in the list start with 1
array start with index of 0
I'm not changing the internal id but using as a lookup
b
dont use an internal id as an index for an array
👍 1
s
an other ideas
b
use an Object
s
Just curious why object is better then array ? Which is more efficient ?less mistakes etc
b
arrays indexes correspond to position, with the first element being index 0 and the one after that 1
objects are indexed by string keys, which are not limited to numbers, nor to being sequential
internal ids are not sequential numbers, there is no requirement that the first one be internal id 0, or the second one internal id 1
s
I know that ,in this case why is one better the keys are the internal id
b
internal ids as keys to an object will prepare you for the eventually where your internal id as array index strategy creates sparse arrays
s
i see that makes sense , thinking about the future
b
if you are not using something as an array, dont use an array
s
let's say you need to loop thru whole "object/array" then array is better even if there is not important index
so I wouldn't make a statement -- "if you are not using something as an array, dont use an array "
b
the array iteration will have you loop through empty indexes
object iteration would not
s
why do you assume there are empty indexes ?
b
what are your internal ids
s
Everything is all good I was just saying you can't make a general rule don't use arrays unless...
b
arrays are objects
with specific functionality related to numbers corresponding to indexes
if you are using an array over an object, the expectation is that you are using array features
💯 1