当前位置:网站首页>(一)代码输出题 —— 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。
边栏推荐
- 一次跳出最外层循环
- [Win11] PowerShell cannot activate Conda virtual environment
- 从事功能测试1年,裸辞1个月,找不到工作的“我”怎么办?
- 批量--09---批量读文件入表
- 热爱和责任
- The most authoritative information query steps for SCI journals!
- Centos7下使用systemd管理redis服务启动
- 深蓝学院-手写VIO作业-第二章
- 科研笔记(七) 基于路径规划和WiFi指纹定位的多目的地室内导航
- OpenPCDet environment configuration of 3 d object detection and demo test
猜你喜欢
随机推荐
分布式系统的一致性与共识(1)-综述
数据可视化之百变柱状图
吴恩达机器学习系列课程笔记——第十六章:推荐系统(Recommender Systems)
Visual SLAM Lecture Fourteen - Lecture 13 Practice: Designing a SLAM system (the most detailed code debugging and running steps)
CaDDN code debugging
CaDDN代码调试
MySQL读写分离mysql-proxy部署
节流阀和本地存储
this指向问题
offset、client 和 scroll
科研笔记(八) 深度学习及其在 WiFi 人体感知中的应用(下)
Reinforcement Learning (Chapter 16 of the Watermelon Book) Mind Map
不会多线程还想进 BAT?精选 19 道多线程面试题,有答案边看边学
EasyCVR视频广场切换通道,视频播放协议异常的问题修复
【每日一题】1374. 生成每种字符都是奇数个的字符串
数据复制系统设计(3)-配置新的从节点及故障切换
高等数学(第七版)同济大学 总习题三(后10题) 个人解答
3D目标检测之数据集
The CCF brush topic tour - the first topic
MySQL read-write separation mysql-proxy deployment