EdwardZZZ / articles

工作点滴记录
2 stars 0 forks source link

数组字符串部分方法参数为负数用法 #18

Open EdwardZZZ opened 7 years ago

EdwardZZZ commented 7 years ago
const str = 'abcdefg'

console.log(str.substr(-1));
// g

console.log(str.substring(str.length - 1));
// g

const arr = [1, 2, 3, 4, 5, 6, 7]

console.log(arr.slice(-1), arr);
// [7] [1, 2, 3, 4, 5, 6, 7]

console.log(arr.splice(-1), arr);
// [7] [1, 2, 3, 4, 5, 6]