当前位置:网站首页>(一)代码输出题 —— 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。
边栏推荐
- Centos7下使用systemd管理redis服务启动
- 吴恩达机器学习系列课程笔记——第十八章:应用实例:图片文字识别(Application Example: Photo OCR)
- 单目三维目标检测之CaDDN论文阅读
- 吴恩达机器学习系列课程笔记——第十三章:聚类(Clustering)
- Location、navigator和History对象
- 使用Ansible编写playbook自动化安装php7.3.14
- 多主复制下处理写冲突(3)-收敛至一致的状态及自定义冲突解决逻辑
- [Study Notes] How to Create an Operation and Maintenance Organizational Structure
- VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tupl
- micro-ros arduino esp32 ros2 笔记
猜你喜欢
随机推荐
ScholarOne Manuscripts submits journal LaTeX file and cannot convert PDF successfully!
详解CAN总线:什么是CAN总线?
jetracer_pro_2GB AI Kit system installation instructions
深蓝学院-视觉SLAM十四讲-第四章作业
MySQL8.0与MySQL5.7区别
MapFi论文架构整理
Your device is corrupt. It cant‘t be trusted and may not work propely.
OpenPCDet environment configuration of 3 d object detection and demo test
科研笔记(八) 深度学习及其在 WiFi 人体感知中的应用(下)
Centos7下使用systemd管理redis服务启动
Platts Analysis-MATLAB Toolbox Function
【FreeRTOS】12 任务通知——更省资源的同步方式
Deep Blue Academy - 14 Lectures on Visual SLAM - Chapter 7 Homework
Win8.1下QT4.8集成开发环境的搭建
科研笔记(六) 基于环境感知的室内路径规划方法
复制延迟案例(4)-一致前缀读
The CCF brush topic tour - the first topic
如何将PDF中的一部分页面另存为新的PDF文件
ROS visualization of 3D target detection
Research Notes (8) Deep Learning and Its Application in WiFi Human Perception (Part 2)









