当前位置:网站首页>(一)代码输出题 —— reverse
(一)代码输出题 —— reverse
2022-08-02 03:58:00 【showbuger】
var arr1 = "ab".split('');
var arr2 = arr1.reverse();
var arr3 = "abc".split('');
arr2.push(arr3);
console.log(arr1.length);
console.log(arr1.slice(-1));
console.log(arr2.length);
console.log(arr2.slice(-1));
答案:
3 ['a', 'b', 'c'] 3 ['a', 'b', 'c']
从答案我们可以看出,arr1和arr2的输出结果是一样的。
这是因为,reverse() 会返回数组的引用!贴上MDN的解释:The reverse method transposes the elements of the calling array object in place, mutating the array, and returning a reference to the array.
reverse 方法颠倒数组中元素的位置,改变了数组,并返回该数组的引用。
所以,改变了arr2其实也就改变了arr1。
边栏推荐
- Your device is corrupt. It cant‘t be trusted and may not work propely.
- MySQL读写分离mysql-proxy部署
- 深度学习基础之batch_size
- 数据可视化之百变柱状图
- 什么是接触电流怎么测?
- ScholarOne Manuscripts submits journal LaTeX file and cannot convert PDF successfully!
- Andrew Ng's Machine Learning Series Course Notes - Chapter 18: Application Example: Image Text Recognition (Application Example: Photo OCR)
- Deep Blue Academy-Visual SLAM Lecture 14-Chapter 6 Homework
- 深蓝学院-视觉SLAM十四讲-第四章作业
- CaDDN代码调试
猜你喜欢

ADSP21489工程中LDF文件配置详解

吴恩达机器学习系列课程笔记——第十八章:应用实例:图片文字识别(Application Example: Photo OCR)

CaDDN paper reading of monocular 3D target detection

深度学习基础之批量归一化(BN)

吴恩达机器学习系列课程笔记——第十六章:推荐系统(Recommender Systems)

Jetson Nano 2GB Developer Kit Installation Instructions

科研笔记(五) SLAC WiFi Fingerprint+ Step counter融合定位

什么是接触电流怎么测?

轮询和长轮询的区别

AFMG SysTune1.3.7使用图解
随机推荐
Location、navigator和History对象
数据可视化之百变柱状图
Research Notes (6) Indoor Path Planning Method Based on Environment Perception
吴恩达机器学习系列课程笔记——第六章:逻辑回归(Logistic Regression)
ScholarOne Manuscripts submits journal LaTeX file and cannot convert PDF successfully!
数学建模学习(76):多目标线性规划模型(理想法、线性加权法、最大最小法),模型敏感性分析
高等数学(第七版)同济大学 总习题三(前10题) 个人解答
从事功能测试1年,裸辞1个月,找不到工作的“我”怎么办?
Sentinel熔断之非控制台方式总结
分布式系统的一致性与共识(1)-综述
Qt处理传输协议数据时QByteArray添加多字节的使用案例
ScholarOne Manuscripts提交期刊LaTeX文件,无法成功转换PDF!
DOM系列之 click 延时解决方案
多主复制下处理写冲突(4)-多主复制拓扑
VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tupl
internship:数据库表和建立的实体类及对应的枚举类之间的联系示例
Zabbix删除一些大表历史数据脚本
ADSP21489仿真:Failed to set breakpoint: Can‘t set breakpoints in the current state: Running
Batch normalization (BN) based on deep learning
Qt编写物联网管理平台49-设备模拟工具