Possible bug in JavaScript editor

I get a warning stating “The method join() is undefined for object ” for “join()” function in code below:

function isThisABug(){
	
	var test = {element: []},
		str = '';
	
	test.element[0] = ['Apple', 'Orange', 'Banana'];
	
	str = test.element[0].join(',');
	
	
	
	application.output(str);
	
}

However the code runs as expected. This looks like a bug and I wasn’t able to find a workaround yet (although I solved the problem by re-working the algorithm in the program).

Attaching a screenshot as well.

Hi,

Adding JSDoc above your variable list will make servoy understand what kind of variable the objects contains.

	/**@type {{element: Array<Array<String>>}}*/
	   var test = {element: []},
	   		/** @type {String} */
	   	   str,
	   	   /**@type {String}*/
		   str2;
	   
	   test.element[0] = ['Apple', 'Orange', 'Banana'];
	   test.element[1] = ['Hello', 'world', 'Banana'];
	   
	   str = test.element[1].join(',');
	   str2 = test.element[0].join(',');
	   
	   application.output(str);
	   application.output(str2);

Here you would not get any warnings and also able to get the code completion for Array.

Output:

Hello,world,Banana
Apple,Orange,Banana

Hope this will help you.

Thanks,

Ic, thanks.

For more info, read this page on our wiki: Annotating JavaScript Using JSDoc.

in this case even this was already fixing it:

     var tst = {element: [[]]},
     str = '';
     tst.element[0] = ['Apple', 'Orange', 'Banana'];
     str = tst.element[0].join(',');
     application.output(str);

so just init the element directly as an array of arrays…