【摘要】 JS语法_基础回顾考必过小编为大家整理了关于JS语法_基础回顾的信息,希望可以帮助到大家!
JS语法_基础回顾
标签:onsconsole字符串拼接i++pre回顾logstr1start
数组方法
push
// log
Array.prototype.$push = function () {
for (let i = 0; i < arguments.length; i++) {
this[this.length] = arguments[i]
}
return this.length
}
let arr = [1, 2]
console.log(arr.$push(3, 4))
console.log(arr)
join
// log
let str1 = ‘1‘
let str2 = ‘2‘
let str3 = ‘3‘
let str4 = ‘4‘
let str5 = ‘5‘
let str6 = ‘6‘
let arr = [str1, str2, str3, str4, str5, str6]
let strFinal = ‘‘
function f1() {
for (let i = 0; i < arr.length; i++) {
strFinal += arr[i]
}
}
function f2() {
strFinal += arr.join(‘‘)
}
{
let start = new Date().getTime()
for (let i = 0; i < 100000; i++) {
f1()
}
let end = new Date().getTime()
console.log(‘字符串拼接耗时: ‘ + (end - start))
}
{
let start = new Date().getTime()
for (let i = 0; i < 10000; i++) {
f2()
}
let end = new Date().getTime()
console.log(‘join耗时: ‘ + (end - start))
}
类数组
// log
let obj = {
1: ‘a‘,
2: ‘b‘,
3: ‘c‘,
length: 3,
push: Array.prototype.push
}
obj.push(‘d‘)
console.log(obj)
JS语法_基础回顾
标签:onsconsole字符串拼接i++pre回顾logstr1start
以上就是JS语法_基础回顾的内容,更多资讯请及时关注考必过网站,最新消息小编会第一时间发布,大家考试加油!