DEV Community

Anjali Gurjar
Anjali Gurjar

Posted on

JS Question 1

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
let x = [];

for (let i = 0; i < arr.length; i += 3) {
x.push(arr.slice(i, i + 3));
}

console.log(x);
// Output: [[1,2,3],[4,5,6],[7,8,9]]

Top comments (0)