let str = '12345'
// ['1','2','3','4','5']
console.log(Array.from(str))
let obj = {
'0': 'a',
'1': 'b',
'2': 'c',
length: 3
};
// ES5 的写法 ['a', 'b', 'c']
console.log([].slice.call(obj))
// ES6 的写法 ['a', 'b', 'c']
console.log(Array.from(obj))
Array.from(arrayLike, x => x * x);
// 等同于
Array.from(arrayLike).map(x => x * x);
// [1, 4, 9]
Array.from([1, 2, 3], x => x * x)
let user = [
{ id: 1, name: "小A" },
{ id: 2, name: "小B" },
{ id: 3, name: "小C" },
{ id: 4, name: "小D" }
];
let name = Array.from(user, ({ name }) => name);
// ['小A','小B','小C','小D']
console.log(name)
function countSymbols(string) {
return Array.from(string).length;
}
// 由于参数不同而导致的重载
// []
console.log(Array())
// [empty × 3]
console.log(Array(3))
// [1, 2, 3]
console.log(Array(1,2,3))
// []
console.log(Array.of())
// [3]
console.log(Array.of(3))
// [1, 2, 3]
console.log(Array.of(1,2,3))
// [null]
console.log(Array.of(null))
// [undefined]
console.log(Array.of(undefined))
Array.prototype.copyWithin(target, start = 0, end = this.length)
// 1号位置开始(234567)被(1234567)替换成(123456)
// [1,1,2,3,4,5,6]
console.log([1,2,3,4,5,6,7].copyWithin(1))
// 0号位置开始(1234567)被(34567)替换成(3456767)
// [3,4,5,6,7,6,7]
console.log([1,2,3,4,5,6,7].copyWithin(0,2))
// 2号位置开始(34567)被(56)替换成(56567)
// [1,2,5,6,5,6,7]
console.log([1,2,3,4,5,6,7].copyWithin(2,4,6))
// 按理来说不会写负数把,谁这么变态
// -3代表右边第3位开始(567)被-5右边第5位到-3右边第3位(34)替换成(347)
// [1,2,3,4,3,4,7]
console.log([1,2,3,4,5,6,7].copyWithin(-3,-5,-3))
let arr = [1,2,3,4,5]
// 1 因为只返回第一个符合条件的
console.log(arr.find(n => n > 0))
// undefined
console.log(arr.find(n => n < 0))
let num = [1,2,3,4,5].find((value,index,arr) => {
return value > 3
})
// 4
console.log(num)
let arr = [1,2,3,4,5]
// 0 因为只返回第一个符合条件的
console.log(arr.findIndex(n => n > 0))
// -1
console.log(arr.findIndex(n => n < 0))
let num = [1,2,3,4,5].findIndex((value,index,arr) => { return value > 3 })
// 3
console.log(num)
let arr = [1,2,3,4,5]
// 5 从右边开始找
console.log(arr.findLast(n => n > 0))
// undefined
console.log(arr.findLast(n => n < 0))
let num = [1,2,3,4,5].findLast((value,index,arr) => { return value > 3 })
// 5
console.log(num)
let arr = [1,2,3,4,5]
// 4
console.log(arr.findLastIndex(n => n > 0))
// -1
console.log(arr.findLastIndex(n => n < 0))
let num = [1,2,3,4,5].findLastIndex((value,index,arr) => { return value > 3 })
// 4
console.log(num)
此页面不支持夜间模式!
已进入夜间模式!
已进入普通模式!
搜索框不允许为空
签到成功!经验+5!芋圆币+2!
签到失败!今日已签到!
需要登录社区账号才可以进入!