JavaScript Array concat method

preview_player
Показать описание
A quick and efficient method to combine two or more arrays and still maintain the individual elements in the finished array.
Using unshift( ) or push( ) will add the whole array as a single element in the new array. If we wanted to add the elements individually then we would either have to use a loop and call push repeatedly OR we can use the concat( ) method and complete the same work with a single line of code.
The added benefit is that we can chain other Array methods at the end.

Рекомендации по теме
Комментарии
Автор

What I love so much about learning javascript from these videos is I don't know how I'll be using each of these methods in the future necessarily, but I'm so excited to try them all out to make something cool. Thank you.

ryanbooth
Автор

Thank you very much, once a student gets used to your standard, I am afraid it will be a trouble for other teachers. My gratitude to you.

rotrose
Автор

Did anybody else try to empty this guys trash bin?

RobertMcHalffey
Автор

Great video, really helped me though you should have said that the sort() method converts them first to strings and then sorts them because if there was a 11 it would be put before 2 i think.

MEZOMEZO
Автор

Hello experts, can anyone explain or share youtube link on how does concat() actually work behind the curtain?
Thanks in advance

akshattambe
Автор

In some of those cases are there any product arrays that are copy by reference. Or all are copy by value, i.e. completely different arrays.

iliashterev
Автор

Thank you very much 😊.. please put Index number to your videos..it would be more helpful..

kushagrasamrat
Автор

Why would we use a loop combined with either push or unshift, when push and unshift work perfectly on their own with a spread operator? Can we say that the 2 statements below are the same?

1. a.push (...b)
2. a.concat(b)

Thank you

zooneyl
Автор

Question: why is the 5 and 500 being treated as the same value in the sort function ?




let array = [1, 5, 3, 4, 5, 6, 7, 500, 873, 888, 900];


let newarr = array.filter(function(num){
if(num%2 == 0){
return num;
}else{
return null;
}
});
console.log(array);
console.log(newarr);


let final = newarr.concat(array);
console.log(final);
let d = final.sort();
console.log(d);

OUTPUT :
[ 1, 5, 3, 4, 5, 6, 7, 500, 873, 888, 900 ]
[ 4, 6, 500, 888, 900 ]
[ 4, 6, 500, 888, 900, 1, 5, 3, 4, 5, 6, 7, 500, 873, 888, 900 ]
[ 1, 3, 4, 4, 5, 5, 500, 500, 6, 6, 7, 873, 888, 888, 900, 900 ]

justaprogrammer
join shbcf.ru