首页 > 编程知识 正文

截取数组第三wwu,shell截取数组

时间:2023-05-05 00:51:30 阅读:194583 作者:3494

示例数组 let testArray = ['a', 'b', 'c', 'd', 'e']; 使用length属性截取 testArray.length = 3;console.info(testArray); // [ "a", "b", "c" ] 使用slice截取(推荐,执行快),注意执行后不改变原数组 testArray = testArray.slice(0, 2); // [ "a", "b" ] 获取数组最后的元素 let newArray = ['a', 'b', 'c', 'd', 'e'];newArray.slice(-1); // [ "e" ]

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。