0

I'm trying to do arr.slice and convert it to json for get request but I get error TypeError: arr.slice is not a function

const splitArray = (req, res, arr = shuffled, n = 4) => {
    if (n < 2) {
        return arr
    }
    let size;
    let result = [];
    for (let i = 0; i < arr.length; i++) {
        if (arr.length % n === 0) {
            size = arr.length / n
            while (i < arr.length) {
                result.push(arr.slice(i, i += size))
            }
        } else {
            while (i < arr.length) {
                size = Math.floor(arr.length / n)
                result.push(arr.slice(i, i += size))
            }
        }
    }
    JSON.stringify({ result }).then((result) => res.send({ result })).catch()
}

app.get('/cards', splitArray)

0 Answers0