Answer the question
In order to leave comments, you need to log in
How to split an array into n number of elements?
There is an array
const = [
{
id: 1,
title: Title1
},
{
id: n,
title: Titlen
}
]
Answer the question
In order to leave comments, you need to log in
$url = preg_replace('/page_[0-9]+\//', '', '/catalog/masla-zhidkosti-i-smazki/page_2/');
// так?
const arr = [{
id: 1,
title: "title1"
}, {
id: 2,
title: "title2"
}];
let result = arr.map(item => Array.of(item));
console.log(result); //
The implementation of what is called on the forehead, but it should be a shame for the fact that you don’t want to think about it. Or are you the breed of StackOverflow programmers?
function split(input, chunkSize){
if(!chunkSize || !Array.isArray(input)){
return input;
}
const result = [];
for(let i = 0; i < input.length; i += chunkSize){
result.push(input.slice(i, chunkSize + i));
}
return result;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question