Worklight Javascript Adapter: Unable to retrieve array value passed as parameter to adapter
I pass a array to the Worklight adapter, and I am unable to retrieve the value in my array.
Inside my -impl.js file, i create a function like:
function getlist(list) { ... }
list is an array. And in my adapter, I try to output the value.
WL.Logger.info(list); WL.Logger.info(list.arr);
It output like:
[INFO ] { "arr": [ { "a": "...", "b": "..." }, { "a": "...", "b": "..." }, { "a": "...", "b": "..." }, ] } [project test] [INFO ] undefined [project test]
I just do not get it. list is first output, which is fine. However, list.arr is the second one and it says undefined. Why list.arr is undefined?
No idea what is wrong.
WL verison: 6.0.0.20130614-0631
Answers
Your list argument IS an array. However the output of a WL.Logger.*() must always be an object (mandated by underlying JS engine). So your array is converted to object for logging purposes. E.g. if your list object is
[1,2,3]
the WL.Logger.debug(list) will be
{ arr: [1,2,3] }
The original object is not modified, it will remain an array. You can still get elements with list[0], list[1] etc.