总结
为了帮助大家更好温习重点知识、更高效的准备面试,特别整理了《前端工程师面试手册》电子稿文件。
内容包括html,css,JavaScript,ES6,计算机网络,浏览器,工程化,模块化,Node.js,框架,数据结构,性能优化,项目等等。
包含了腾讯、字节跳动、小米、阿里、滴滴、美团、58、拼多多、360、新浪、搜狐等一线互联网公司面试被问到的题目,涵盖了初中级前端技术点。
前端面试题汇总
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
JavaScript
性能
linux
console.log(firstHalf); // [1, 2, 3]
console.log(secondHalf); // [4, 5, 6]
console.log(list); // []
Array.splice()
方法通过删除,替换或添加元素来更改数组的内容。 而Array.slice()
方法会先对数组一份拷贝,在操作。
-
list.splice(0, middleIndex)
从数组的0
索引处删除前3
个元素,并将其返回。 -
splice(-middleIndex)
从数组中删除最后3
个元素并返回它。
在这两个操作结束时,由于我们已经从数组中删除了所有元素,所以原始数组是空的。
另请注意,在上述情况下,元素数为偶数,如果元素数为奇数,则前一半将有一个额外的元素。
const list = [1, 2, 3, 4, 5];
const middleIndex = Math.ceil(list.length / 2);
list.splice(0, middleIndex); // returns [1, 2, 3]
list.splice(-middleIndex); // returns [4, 5]
有时我们并不希望改变原始数组,这个可以配合 Array.slice() 来解决这个问题:
const list = [1, 2, 3, 4, 5, 6];
const middleIndex = Math.ceil(list.length / 2);
const firstHalf = list.slice().splice(0, middleIndex);
const secondHalf = list.slice().splice(-middleIndex);
console.log(firstHalf); // [1, 2, 3]
console.log(secondHalf); // [4, 5, 6]
console.log(list); // [1, 2, 3, 4, 5, 6];
我们看到原始数组保持不变,因为在使用Array.slice()
删除元素之前,我们使用Array.slice()
复制了原始数组。
const list = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const threePartIndex = Math.ceil(list.length / 3);
const thirdPart = list.splice(-threePartIndex);
const secondPart = list.splice(-threePartIndex);
const firstPart = list;
console.log(firstPart); // [1, 2, 3]
console.log(secondPart); // [4, 5, 6]
console.log(thirdPart); // [7, 8, 9]
简单解释一下上面做了啥:
-
首先使用
st.splice(-threePartIndex)
提取了ThirdPart,它删除了最后3个元素[7、8、9]
,此时list
仅包含前6个元素[1、2、3、4、5、6]
。 -
接着,使用
list.splice(-threePartIndex)
提取了第二部分,它从剩余list = [1、2、3、4、5、6]
(即[4、5、6])中删除了最后3个元素,list仅包含前三个元素[1、2、3]
,即firstPart
。
现在,我们来看一看 Array.splice() 更多用法,这里因为我不想改变原数组,所以使用了 Array.slice(),如果智米们想改变原数组可以进行删除它。
const list = [1, 2, 3, 4, 5, 6, 7, 8, 9];
获取数组的第一个元素
list.slice().splice(0, 1) // [1]
获取数组的前5个元素
list.slice().splice(0, 5) // [1, 2, 3, 4, 5]
最后
正值招聘旺季,很多小伙伴都询问我有没有前端方面的面试题!
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
) // [1, 2, 3, 4, 5]
最后
正值招聘旺季,很多小伙伴都询问我有没有前端方面的面试题!
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
[外链图片转存中…(img-HDmNHl2Y-1715749656711)]