Asked 6 years ago
24 Mar 2018
Views 1708
jaggy

jaggy posted

how to merge array in javascript ?


var result1 =["data1","data2"];
var result2 =["data3","data4"];


so i try to join one array with another one


var result = result1 + result2 ;


is that work with like as we do with string concatenation ?
angeo

angeo
answered Nov 30 '-1 00:00

one can use forEach and push method to merge two array as well


var animals1 = ['pigs', 'goats', 'sheep'];
var animals2 = ['dog', 'lion', 'bear'];
animals2.forEach(function(value){ animals1 .push(value); })
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

+ only use for string merging not for array in javascript

its simple

		var result = result.concat(result2);
		console.log(result);


Post Answer