this code doesn't work
var arr1 = ["a", "b", "c"];
var arrayJoin=[];
arrayJoin.concat(arr1.filter(function (val) {
return val == "a";
}));
console.log(arrayJoin);
this works fine
arrayJoin=arr1.filter(function (val) {
return val == "a";
}));
any idea how to concat the filter array?
this code doesn't work
var arr1 = ["a", "b", "c"];
var arrayJoin=[];
arrayJoin.concat(arr1.filter(function (val) {
return val == "a";
}));
console.log(arrayJoin);
this works fine
arrayJoin=arr1.filter(function (val) {
return val == "a";
}));
any idea how to concat the filter array?
Share Improve this question asked Dec 14, 2016 at 20:43 baarozbaaroz 19.6k8 gold badges38 silver badges48 bronze badges 3-
3
Array.prototype.concat()
[...]The concat() method is used to merge two or more arrays. This method does **not** change the existing arrays, but instead **returns a new** array.[...]
– t.niese Commented Dec 14, 2016 at 20:47 -
1
Array.prototype.filter() returns a new Array, so what do you need
concat
for – DavidDomain Commented Dec 14, 2016 at 20:49 - this is one concat in a series – baaroz Commented Dec 14, 2016 at 20:51
1 Answer
Reset to default 5What about
arrayJoin = arrayJoin.concat(arr1.filter(function (val) {
return val == "a";
}));