如何调用JavaScript数组中定义的函数

如何调用JavaScript数组中定义的函数,javascript,arrays,Javascript,Arrays,下面是我的代码,当我试图控制台数组中定义的函数时,它抛出了一个错误。让我知道我做错了什么 var a = ['This is a string', {'name': 'Test User'}, 90, undefined, 'Another String', null, function(){return 'This is also valid'}]; for(var i=0; i<a.length; i++) { if(typeof a[i] === 'function')

下面是我的代码,当我试图控制台数组中定义的函数时,它抛出了一个错误。让我知道我做错了什么

var a = ['This is a string', {'name': 'Test User'}, 90, undefined, 'Another String', null, function(){return 'This is also valid'}];

for(var i=0; i<a.length; i++) {
  if(typeof a[i] === 'function')
    console.log(a[i]());
  else
    console.log(a[i]());
}

从else中删除方法调用

for(var i=0; i<a.length; i++) {
  if(typeof a[i] === 'function')
    console.log(a[i]());
  else
    console.log(a[i]); //remove method call from here
}

for(var i=0;iCheck
else
part。是否需要将其称为函数?@Tushar您在我之前20秒就回答了这个问题。如果该方法不是函数类型,它将给出一个错误。
for(var i=0; i<a.length; i++) {
  if(typeof a[i] === 'function')
    console.log(a[i]());
  else
    console.log(a[i]); //remove method call from here
}