Answering my own question... On digging and debugging, I came across the correct line in the javascript file at which the object is null and simply included a code to avoid null value. For eg:
if(text != null)
{
Enter your code....
}
else
{
arr=0;
}
return arr;