let array = ['1', '2', '3'];
array[5] = 'A';
console.log(array);
数组1.concat(数组2,数组3,…,数组n);
arrayObject.concat(arrayX,arrayX,......,arrayX);
let arr = [1,2,3]
// [1,2,3,1,2]
console.log(arr.concat([1,2]))
// [1,2,3]
console.log(arr)
数组对象.join("分隔符");
arrayObject.join(separator);
let arr=[1,2,3]
// '1,2,3'
console.log(arr.join())
// '1*2*3'
console.log(arr.join("*"))
数组对象.pop();
arrayObject.pop();
let arr = [1,2,3,4,5]
// 5
console.log(arr.pop())
// [1,2,3,4]
console.log(arr)
数组对象.push(新元素1,新元素2,…,新元素n);
arrayObject.push(newelement1,newelement2,....,newelementX);
let arr = [1,2,3,4,5]
// 7
console.log(arr.push(1,2))
// [1,2,3,4,5,1,2]
console.log(arr)
数组对象.reverse();
arrayObject.reverse();
let arr = [1,2,3,4,5]
// [5,4,3,2,1]
console.log(arr.reverse())
// [5,4,3,2,1]
console.log(arr)
arrayObject.shift();
let arr = [1,2,3,4,5]
// 1
console.log(arr.shift())
// [2,3,4,5]
console.log(arr)
数组对象.unshift(新元素1,新元素2,…,新元素n);
arrayObject.unshift(newelement1,newelement2,....,newelementX);
let arr = [1,2,3,4,5]
// 6
console.log(arr.unshift(5))
// [5,1,2,3,4,5]
console.log(arr)
数组对象.slice(start,end);
arrayObject.slice(start,end)
let arr = [1,2,3,4,5]
// [2,3]
console.log(arr.slice(1,3))
// [1,2,3,4,5]
console.log(arr)
数组对象.sort(函数名);
arrayObject.sort(sortby);
let arr = [5,2,11,16,1,22,8,25]
// 根据ASCII字符排序
// [1,11,16,2,22,25,5,8]
console.log(arr.sort())
// a - b升序
// [1,2,5,8,11,16,22,25]
let arr1 = arr.sort((a, b) => a - b)
console.log(arr1)
// b - a升序
// [25,22,16,11,8,5,2,1]
let arr2 = arr.sort((a, b) => b - a)
console.log(arr2)
arrayObject.splice(index,howmany,item1,.....,itemX);
let arr1 = [1,2,3,4,5]
// [3,4]
console.log(arr1.splice(2,2))
// [1,2,5]
console.log(arr1)
let arr2 = [1,2,3,4,5]
// []
console.log(arr2.splice(2,0,5,6))
// [1,2,5,6,5]
console.log(arr2)
arrayObject.valueOf();
数组对象.toString();
arrayObject.toString();
let arr = [1,2,3,4,5]
// '1,2,3,4,5'
console.log(arr.toString())
arrayObject.toLocaleString();
object.toSource();
function employee(name, job, born) {
this.name = name;
this.job = job;
this.born = born;
}
var bill = new employee("Bill Gates", "Engineer", 1985);
// ({name:"Bill Gates", job:"Engineer", born:1985})
console.log(bill.toSource())
此页面不支持夜间模式!
已进入夜间模式!
已进入普通模式!
搜索框不允许为空
签到成功!经验+5!芋圆币+2!
签到失败!今日已签到!
需要登录社区账号才可以进入!