Is there a good way to convert a list of items with no more than 1 item in it to a single item? There are 2 ways I know of, both have minor issues depending on the context.
1) use an index such as array[1] to get the first value of the array - This works, but requires some null checking in case the array is empty as it will bug out if that is the case.
2) use cast, but this requires knowing the type ahead of time, and if that's not possible, neither is this casting method.
Is there any other way I'm missing? Some hidden fromList() function I haven't found yet?
Discussion posts and replies are publicly visible
index(ri!list, 1, null())
Thanks! That seems perfect.
Index is returning another array. Why is that?
It can happen if you are passing multiple indexes i.e. index({10, 20, 30}, {1, 3}, null) returns {10,30}. What is your use case please share some more info for better understanding.
Darwin Pou said:Index is returning another array. Why is that?
It depends on what data you're passing in and how you're calling it. Can you share your input data, your code, and your output data?
Thanks. I think the problem was in bold part.
a! localVariables(
local!a: {1,2,3,4,5}
local!a[1]
)
The problem is with the brackets itself. remove those
Darwin Pou said: I think the problem was in bold part.
I don't see where "index()" is involved with the sample code you posted. It looks like something else may have gotten messed up in translation too.
I think what he was saying is Output of his code coming as Array where he is only indexing one value, he enclosed the output in Curly braces
I changed the index function with something easier to test, and problem were the brackets. Thanks.