简体   繁体   English

这两个Javascript数组有什么区别?

[英]What is the difference between these two Javascript arrays?

在此处输入图片说明

One is built like this: 一个这样构建:

var l1 = [23, 50, 63, 90, 10, 30, 155, 23, 18]

And the other is having elements pushed into it via browser automation: 另一个是通过浏览器自动化将元素推入其中:

var test = []
list1.each(($el) => {
    return test.push(+$el.get(0).innerText)
})

First one is mutated after logging, second one is logged after mutating. 第一个记录发生突变,第二个在发生变化记录。 Try the following in the console: 在控制台中尝试以下操作:

var arr = [];
console.log(arr);//will log [] but can expand to an item with name 'one'
console.table(arr);//the actual value of arr at the time of logging
console.log(JSON.stringify(arr));//also actual value when logging
arr.push({name:'one'})

I believe .each returns an object with the value. 我相信.each返回带有值的对象。 So if you where to get the type of the $el than it would return obj and not number. 因此,如果在何处获取$ el的类型,则它将返回obj而不是数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM