Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 关联数组:定义未定义的数组?_Javascript_Regex_Arrays_Associative Array - Fatal编程技术网

Javascript 关联数组:定义未定义的数组?

Javascript 关联数组:定义未定义的数组?,javascript,regex,arrays,associative-array,Javascript,Regex,Arrays,Associative Array,我刚刚尝试了以下代码(javascript),该代码应返回“This is verally undefined”,但不起作用: var foo = {'foo' : 'bar', undefined : 'This is totally undefined!'}; alert( foo['toomany foobars'.match(/asdf/)] ); 然而,这是完美的: var foo = {'foo' : 'bar', undefined : 'This is totally u

我刚刚尝试了以下代码(javascript),该代码应返回“This is verally undefined”,但不起作用:

 var foo = {'foo' : 'bar', undefined : 'This is totally undefined!'};
 alert( foo['toomany foobars'.match(/asdf/)] );
然而,这是完美的:

 var foo = {'foo' : 'bar', undefined : 'This is totally undefined!'};
 alert(foo[undefined]);
我不明白,有人能解释吗

提前多谢

那是因为

'toomany foobars'.match(/asdf/) === null
null !== undefined
另一方面,如果你有这个

var foo = {'foo' : 'bar', undefined : 'This is totally undefined!', null: 'and this one is null'};
alert( foo['toomany foobars'.match(/asdf/)] );
你会看到它起作用的



发生这种情况的原因是
undefined
是JavaScript中的一个值,
null
是另一个值。当您在字典中使用这两个查找时,它们将返回(并且应该返回)不同的结果。

我刚刚尝试定义null,它返回“这是完全未定义的”,谢谢。。。很抱歉我自己没有想到这一点