I have an application that allows users to write javascript for custom tasks on a set of files, it works on metadata in the files and the metadata is bound to the javascript. The metadata for different files can be different and a field defined in one file may not exist in another. When a particular piece of metadata contains multiple values for a file it is returned as an array.
What I wanted was create a function that checked the length of an array whilst coping with the fact that the array may not be defined so that the user could use this without having to check if the array is undefined making their scripting easier. However the function below fails for undefined arrays because it cant pass an undefined varaible to the function in the first place.
function arrayLength(indexedScriptField)
{
if(typeof indexedScriptField !== 'undefined')
{
return indexedScriptField.length;
}
return 0;
}
Is there another way to achieve what I want ?