首页 > 解决方案 > 这两个 Javascript 数组有什么区别?

问题描述

在此处输入图像描述

一个是这样构建的:

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

另一个是通过浏览器自动化将元素推入其中:

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

标签: javascriptarraysstringnumbers

解决方案


第一个在记录后被变异,第二个在变异后被记录。在控制台中尝试以下操作:

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'})

推荐阅读