I am pretty new to Javascript, so this might be a silly question. but is it possible to add arrays together? like...
var m2 = new Array(2).fill(TEST); var m4 = m2 + m2;
or is there another technique in which i can do such a thing? Thank you!
I am pretty new to Javascript, so this might be a silly question. but is it possible to add arrays together? like...
var m2 = new Array(2).fill(TEST); var m4 = m2 + m2;
or is there another technique in which i can do such a thing? Thank you!
One possibility is to use the spread operator ... .
let arr1 = [1,2,3,4];
let arr2 = ['a','b','c'];
let array = [...arr1, ...arr2];
console.log(array);
You can use concat:
const m2 = new Array(2).fill("TEST");
const m4 = m2.concat(m2);
console.log(m2,m4)
Joing two array like []+[] will result to a string. You can merge two array using e destructuring or using concat
var m2 = new Array(2).fill('TEST');
var m4 = [...m2, ...m2];
var m5 = m2.concat(m2)
console.log(m4);
console.log(m5)