How to combine/join arrays using jQuery
Earlier I had posted about jQuery solution to remove item from array, split an array and Find index of element in array, And In this post, find how to combine/join arrays with example.
Below jQuery code joins the two arrays using jQuery.
$(document).ready(function() { var arrFirst = [50, 10, 19, 22]; var arrSecond = [6, 74]; $('#firstPart').html(arrFirst.join()); $('#secondPart').html(arrSecond.join()); var arrJoin = arrFirst.concat(arrSecond); $('#allElements').html(arrJoin.join()); });?
In this jQuery code, I have used the concat() method. contact() is the method of an array object and it is invoked on the first array and the second array is passed to it as a parameter. And it returns another array which is combination of both the arrays elements.
See result below.
Feel free to contact me for any help related to jQuery, I will gladly help you.