我有一个像这样的对象数组:
const books =[
{id: "1", name: "twilight", category: "Movies", price: 10},
{id: "2", name: "jaws", category: "Movies", price: 22},
{id: "3", name: "the shining", category: "Movies", price: 1},
{id: "4", name: "beers", category: "Movies", price: 10},
{id: "5", name: "apples", category: "Movies", price: 22},
{id: "6", name: "mono", category: "Movies", price: 1}
]
尝试每次切割前2本书、接着2本书等。
如何按两本书一组切片?
books.slice(0, 2)
有什么原因吗?这将让你获得前两个,然后你只需要不断增加索引以获取其余的部分。 - IvanS95