gpt4 book ai didi

javascript - 如果数组结束javascript,则从头开始切片

转载 作者:行者123 更新时间:2023-11-29 17:35:12 25 4
gpt4 key购买 nike

所以我正在研究一些过滤器,用户甚至可以从 ex 中选择:“周五到周二”,但是我如何从日期数组中切分这些

var days = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]

那么我如何将索引从 5 切片到 2 应该返回:

["friday", "saturday", "sunday", "monday", "tuesday"]

最佳答案

你可以使用

var days = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]

const selection = [...days.slice(4), ...days.slice(0, 2)];


console.log(selection);

关于javascript - 如果数组结束javascript,则从头开始切片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57138153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com