当前位置:网站首页>(一)代码输出题 —— 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无法激活Conda虚拟环境
Your device is corrupt. It cant‘t be trusted and may not work propely.
UI自动化测试框架搭建——标记性能较差用例
数学建模学习(76):多目标线性规划模型(理想法、线性加权法、最大最小法),模型敏感性分析
Pycharm platform import scikit-learn
多数据中心操作和检测并发写入
七分钟深入理解——卷积神经网络(CNN)
SCI writing strategy - with common English writing sentence patterns
Deep blue college - handwritten VIO operations - the first chapter
ADSP21489工程中LDF文件配置详解
随机推荐
列表总结
ES6中变量的使用及结构赋值
ROS visualization of 3D target detection
科研笔记(八) 深度学习及其在 WiFi 人体感知中的应用(上)
DOM系列之 click 延时解决方案
Arduino框架下STM32F1/F4系列HID模式程序烧录教程
自定义一个下划线分词器
数据可视化之百变柱状图
无主复制系统(1)-节点故障时写DB
多数据中心操作和检测并发写入
ADSP21489仿真:Failed to set breakpoint: Can‘t set breakpoints in the current state: Running
并发性,时间和相对性(1)-确定前后关系
深蓝学院-手写VIO作业-第二章
2022华为软件精英挑战赛(初赛)-总结
PHP5.6安装ssh2扩展用与执行远程命令
Kubernetes中Pod对象学习笔记
How to save a section of pages in a PDF as a new PDF file
Andrew Ng's Machine Learning Series Course Notes - Chapter 18: Application Example: Image Text Recognition (Application Example: Photo OCR)
Location、navigator和History对象
MapFi论文架构整理