Console.log()正在打印同一个变量的两个不同值

Ade*_*ram 0 javascript jquery

我正在运行一个代码,我与你分享,这很简单,在两个不同的console.log()命令的情况下,它返回两个不同的结果.这里的".filter_me"类被分配给一个锚,

$(".filter_me").each(
    function(index,value)
    {    
        console.log(index+" is index and "+value+" is value.");
        //output of above line is "0 is index and "http://www.ex.com/2 
        //is value"{for first anchor,http://www.ex.com/ is base url and
        //2 is value of href of first anchor}
        console.log(value);
        //output of above line is <a href="2" class="filter_me">clk</a>
    });
Run Code Online (Sandbox Code Playgroud)

那么为什么在第一种情况下

value = http://www.ex.com/2

在第二种情况下

value = <a href="2" class="filter_me">clk</a>

Jon*_*nas 5

由于日志中的其他字符串,第一个值将转换为字符串.

第二个值是对象,因为它是日志中唯一的元素.