当前位置:网站首页>(一)代码输出题 —— 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。
边栏推荐
- 力扣 215. 数组中的第K个最大元素
- 温暖的世界
- VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tupl
- 多主复制的适用场景(1)-多IDC
- offset、client 和 scroll
- 科研笔记(八) 深度学习及其在 WiFi 人体感知中的应用(上)
- ROS visualization of 3D target detection
- 强化学习(西瓜书第16章)思维导图
- 吴恩达机器学习系列课程笔记——第十四章:降维(Dimensionality Reduction)
- Pycharm platform import scikit-learn
猜你喜欢
Deep blue college - handwritten VIO operations - the first chapter
Batch normalization (BN) based on deep learning
ROS visualization of 3D target detection
falco 【1】入门
Deep Blue Academy - Visual SLAM Lecture Fourteen - Chapter 5 Homework
2022华为软件精英挑战赛(初赛)-总结
三维目标检测之ROS可视化
普氏分析法-MATLAB工具箱函数
最后写入胜利(丢弃并发写入)
吴恩达机器学习系列课程笔记——第九章:神经网络的学习(Neural Networks: Learning)
随机推荐
Pycharm平台导入scikit-learn
使用docker-compose 安装Redis最新版,并且设置密码
Nexus 5 phone uses Nexmon tool to get CSI information
Your device is corrupt. It cant‘t be trusted and may not work propely.
MapFi paper structure organization
如何解决QByteArray添加quint16双字节时错误?
列表总结
不会多线程还想进 BAT?精选 19 道多线程面试题,有答案边看边学
VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tupl
吴恩达机器学习系列课程笔记——第八章:神经网络:表述(Neural Networks: Representation)
生物识别学习资源推荐
EasyCVR视频广场切换通道,视频播放协议异常的问题修复
offset、client 和 scroll
micro-ros arduino esp32 ros2 笔记
节流阀和本地存储
Reinforcement Learning (Chapter 16 of the Watermelon Book) Mind Map
吴恩达机器学习系列课程笔记——第十五章:异常检测(Anomaly Detection)
分布式系统的一致性与共识(1)-综述
Computer Basics
Anconda spyder内引用OpenCV出现错误ImportError: numpy.core.multiarray failed to import