In this post, we will see that "how to split an array using jQuery". Below jQuery code splits the array using jQuery.
See result below.
Read more about splice() method here.
$(document).ready(function() { var members = [50, 10, 19, 22, 6, 74]; $('#allElements').html(members.join()); memsecond = members.splice(0,4); $('#firstPart').html(memsecond.join()); $('#secondPart').html(members.join()); }); In this jQuery code, I have used the splice() method for splitting the array. This method requires 2 parameters. The first parameter specifies the index location from where to start splitting, and the second parameter specifies the number of elements to be removed from the original array. The range of array elements defined by the two parameters will be extracted from the original array and will be returned so it can be saved in another array.See result below.
Read more about splice() method here.
Also read Split function in jQuery
Feel free to contact me for any help related to jQuery, I will gladly help you.

No comments:
Post a Comment