console.log(a,b)为什么只能输出a,怎样才能让它输出a和b?

<script src="jquery-1.12.3.js"></script>

<script type="text/javascript">

 $(function(){

    var arr = [2,5,6]

     $.each(arr, function(index,items) {

    console.log(index, items)

    });

})

</script>

为什么值能输出索引值0,1,2,items值却输不出来?怎样连后面那个值也输出来呢?

慕码人0004322
浏览 2296回答 1
1回答

习惯受伤

使用格式化字符串 %O 来输出JS对象,因为 index 和 items 都可以看作是 JS对象,所以使用以下的方式输出:console.log("%O, %O", index, items)关于更详细的格式化字符串,前往这里学习
打开App,查看更多内容
随时随地看视频慕课网APP