JavaScript Array concat method

  Рет қаралды 12,320

Steve Griffith - Prof3ssorSt3v3

Steve Griffith - Prof3ssorSt3v3

7 жыл бұрын

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.
Code GIST: gist.github.com/prof3ssorSt3v...

Пікірлер: 25
@chesterxp508
@chesterxp508 2 жыл бұрын
Brilliant tutorials !!!
@ryanbooth1385
@ryanbooth1385 3 жыл бұрын
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.
@rotrose7531
@rotrose7531 4 жыл бұрын
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.
@lovemanga_forever
@lovemanga_forever 3 жыл бұрын
This video help me a lot
@GoodMood666
@GoodMood666 4 жыл бұрын
now i have basic idea about concat
@jsnode2075
@jsnode2075 7 жыл бұрын
Nice, thanks
@Youssef-lv6wp
@Youssef-lv6wp 3 жыл бұрын
Thanks u 😍❤
@RobertMcHalffey
@RobertMcHalffey 5 жыл бұрын
Did anybody else try to empty this guys trash bin?
@MEZOMEZO2011
@MEZOMEZO2011 6 жыл бұрын
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.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
You are correct about the sorting. I have a video where I talk about that too - kzbin.info/www/bejne/eWSogYerjbCFrZI
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
Actually both videos are part of my playlist on JavaScript Arrays - kzbin.info/www/bejne/l6OsmZuImZaFhsU - I will add more Array videos to this list.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
I will be adding a video on custom sorts with JS soon.
@MEZOMEZO2011
@MEZOMEZO2011 6 жыл бұрын
Steve Griffith good luck
@akshattambe
@akshattambe 4 жыл бұрын
Hello experts, can anyone explain or share youtube link on how does concat() actually work behind the curtain? Thanks in advance
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat
@iliashterev38
@iliashterev38 4 жыл бұрын
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.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
Depends on the contents that you are copying - if they are primitive values or Objects. See this video about shallow vs deep copying - kzbin.info/www/bejne/mqbcpJuebqumZ7c
@iliashterev38
@iliashterev38 4 жыл бұрын
​@@SteveGriffith-Prof3ssorSt3v3 Thank you. I went through that course. Thank you for it too. So as far as Objects are concerned it becomes freaky that we have total of six highly praised methods, deeply studied, and none of them does the job to create an entirely different array. What would be the point of making a shallow copy instead of deep one ?? Well, I am sorry for asking once more but are there many dangers when using shallow copies in real life ?? Do you have lecture for that ??
@kushagrasamrat7137
@kushagrasamrat7137 4 жыл бұрын
Thank you very much 😊.. please put Index number to your videos..it would be more helpful..
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
I have lots of playlists on specific topics on my channel homepage. However, I have nearly 700 videos and there is no index number for each video. There is no specific order in which to watch the videos. It would be like trying to number the leaves on a tree.
@justaprogrammer3764
@justaprogrammer3764 5 жыл бұрын
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 ]
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 5 жыл бұрын
Because the Array.sort( ) method does a String sort by default. I have a couple tutorials on this. Array manipulations and sorts - kzbin.info/www/bejne/eWSogYerjbCFrZI Custom Array sorts - kzbin.info/www/bejne/sIfIp59jgJKgbbs
@zooneyl2248
@zooneyl2248 2 жыл бұрын
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
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 2 жыл бұрын
Those two statements do the same thing. I didn't use the spread operator in the example because that is another topic AND it still wasn't widely supported when this video was recorded.
@yarik83men51
@yarik83men51 4 жыл бұрын
+++
JavaScript String.split and Array.join
8:42
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 35 М.
Real World Array Method Uses in JavaScript Web Development
24:18
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 12 М.
КАК ДУМАЕТЕ КТО ВЫЙГРАЕТ😂
00:29
МЯТНАЯ ФАНТА
Рет қаралды 10 МЛН
Manipulating and Sorting Arrays in JavaScript
12:32
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 21 М.
Deep Dive into Array from method
22:05
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 2,6 М.
JavaScript Array filter method
9:15
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 18 М.
Array Methods in JavaScript | 17 Useful Methods
42:39
DoableDanny
Рет қаралды 51 М.
Every JavaScript Developer Has Made This Mistake With Functions
7:17
Web Dev Simplified
Рет қаралды 106 М.
8 Must Know JavaScript Array Methods
10:05
Web Dev Simplified
Рет қаралды 1 МЛН
Playing with JavaScript Objects
11:56
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 29 М.
5 JavaScript Concepts You HAVE TO KNOW
9:38
James Q Quick
Рет қаралды 1,4 МЛН