// ES5 version use Array.concat:
let array1 = ["a", "b"]
let array2 = ["1", "2"]
let combinedArray = array1.concat(array2);
// combinedArray == ["a", "b", "1", "2"]
// ES6 version use destructuring:
let array1 = ["a", "b"]
let array2 = ["1", "2"]
let combinedArray = [...array1, ...array2]
// combinedArray == ["a", "b", "1", "2"]
<?php
$arr1 = array("Geeks", "g4g");
$arr2 = array("GeeksforGeeks", "Computer science portal");
// Get the merged array in the first array itself.
$arr1 = array_merge($arr1, $arr2);
echo "arr1 Contents:";
// Use for each loop to print all the array elements.
foreach ($arr1 as $value) {
echo $value . "
";
}
?>
const arrFirst = ['string1', 'string2'];
const arrSecond = ['string3','string4'];
const newArr = [...arrFirst, ...arrSecond];
console.log(newArr);
const myGirls = ["Cecilie", "Lone"];
const myBoys = ["Emil", "Tobias", "Linus"];
const myChildren = myGirls.concat(myBoys);
function mergeArrays(arr1, arr2) {
return Array.from(new Set(arr1.concat(arr2).sort((a,b) => (a-b))));
}
$users = User::all();
$associates = Associate::all();
$userAndAssociate = $users->concat($associates);
$users = User::all();
$associates = Associate::all();
$userAndAssociate = $users->concat($associates);