Answered by:
Split Json Object.

Question
-
User-930371450 posted
Hi Team,
Please help me how to split string after 5 elements using jquery.
var str=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
1,2,3,4,5
6,7,8,9,10
11,12,13,14,15Wednesday, January 22, 2020 7:20 PM
Answers
-
User475983607 posted
Hi Team,
Please help me how to split string after 5 elements using jquery.
var str=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
1,2,3,4,5
6,7,8,9,10
11,12,13,14,15I'm a little confused because the code shown is not a string it is an integer array.
There are tons of array functions in JavaScript but slice might be what you are looking for.
str.slice(0,5); str.slice(5,10); str.slice(10,15);
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, January 22, 2020 7:35 PM -
User-1780421697 posted
var a = ['a','b','c','d','e','f','g','h','i','j','k']
, chunk
while (a.length > 0) {
chunk = a.splice(0,5)
console.log(chunk)
}
output
[ 'a', 'b', 'c','d','e' ]
[ 'f', 'g', 'h','i','j' ]
[ 'k' ]- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, January 22, 2020 7:41 PM
All replies
-
User475983607 posted
Hi Team,
Please help me how to split string after 5 elements using jquery.
var str=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
1,2,3,4,5
6,7,8,9,10
11,12,13,14,15I'm a little confused because the code shown is not a string it is an integer array.
There are tons of array functions in JavaScript but slice might be what you are looking for.
str.slice(0,5); str.slice(5,10); str.slice(10,15);
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, January 22, 2020 7:35 PM -
User-1780421697 posted
var a = ['a','b','c','d','e','f','g','h','i','j','k']
, chunk
while (a.length > 0) {
chunk = a.splice(0,5)
console.log(chunk)
}
output
[ 'a', 'b', 'c','d','e' ]
[ 'f', 'g', 'h','i','j' ]
[ 'k' ]- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, January 22, 2020 7:41 PM