I create a new array, or rather an empty one, then do some processing on it then pass it on to the function, but seems the function can't use forEach on the array I passed as input to the function, I can write that part of the code directly inside my body of code, but my question is why shouldn't this work?
this is the function I passed my array to:
function checkindex(users) {
var index;
var bool;
users.forEach(element => {
if (msg.payload != element.username) {
bool = false;
}
else {
index = users.findIndex(obj => obj.username == msg.payload);
m_index = index;
bool = true;
}
});
return bool;
}
and this is the parts of my codes body that might be needed for further analysis (note that there is global array users which is then put into my local users variable, and that global variable is an array):
var users = new Object;
users = global.get('users');
let user = { "username": msg.username, "password": msg.password, "Token": msg.token, "Submission-Time": msg.currentTime, "Expiration-Time": msg.tkExpire };
let check = checkindex(users);
if (check)
{
users[m_index] = user;
}
else{}
yeah my bad, instead of creating an array inside my global users, I created a single object with multiple properties, fixed that part and the function works fine.
Although I think it would be more convenient if the function autocomplete module supported more of the JS codes. I mean like IDEs do,
right, although sometimes even if I have initialized it explicitly, it would not work,
but right now I tried it again and it worked, seems in this case the same "defining an object instead of an array" was the culprit.
also most of the time I write my code elsewhere and paste in the node, so I did not realize it works for most of the data-types.