javascript - 这两个 Javascript 数组有什么区别?
问题描述
一个是这样构建的:
var l1 = [23, 50, 63, 90, 10, 30, 155, 23, 18]
另一个是通过浏览器自动化将元素推入其中:
var test = []
list1.each(($el) => {
return test.push(+$el.get(0).innerText)
})
解决方案
第一个在记录后被变异,第二个在变异后被记录。在控制台中尝试以下操作:
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'})
推荐阅读
- rust - Rust 中的红黑树,得到“预期的结构节点,找到可变引用”
- android - OnBackPress 片段
- python - 在 django 视图中理解 request.data
- python - 如何在 python3 kubernetes 客户端中加载 2 个(或更多)不同的 kubeconfig?
- python - 使用 BeautifulSoup 将 XML 中的数据提取到 csv 文件中
- c++ - 在 C++ 中检查 Palidrome,一些输出正在工作,一些则没有
- git - git repo size - git repo 正常工作的大小实际上是多少?
- sql - 为什么忽略 SQL Server 2014 中的空格文本
- java - 为什么图片是黑色的?
- javascript - 我在一页中有 3 个数据表,我需要在每个表中选择一个