标签:ons console 字符串拼接 i++ pre 回顾 log str1 start
// 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)
// 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)
标签:ons console 字符串拼接 i++ pre 回顾 log str1 start
原文地址:https://www.cnblogs.com/oceans/p/13574948.html