企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
[TOC] >[success] # shift() ~~~ '删除数组的第一个元素,并返回该元素'。注意,该方法会改变原数组。 ~~~ ~~~ let arr = ['a', 'b', 'c'] arr.unshift('x') // 4 // 返回数组的最新长度 console.log(arr) // ['x', 'a', 'b', 'c'] shift()方法还可以遍历并清空一个数组。 let list = [1, 2, 3, 4, 5, 6] let item while (item = list.shift()) { // while是条件是true就一直循环 console.log(item) } console.log(list) // [] ~~~