Use Concat to Add Values to an Array

InstructorShane Osbourne

Share this video with your friends

Send Tweet

Concat creates a shallow copy of an existing array that includes any arguments you pass to it. In this lesson, we look at using concat for adding additional values to an array then cover some more useful features such as accepting other arrays as arguments & how to chain concat with other array methods such as forEach

Francesco
~ 9 years ago

Would someone be able to tell me what web editor Shane Osbourne uses during his Array videos? It looks like a really nice simple left / right "repl" output using NodeJS, but i'm not sure which one it is and wanted to try it. Thanks for your time and patience and all of you keep up the great work! - Frankie

Shane Osbourneinstructor
~ 9 years ago

Hi Francesco

It's just https://www.jetbrains.com/webstorm/

Then I have a run configuration setup to a key binding, so at any point I can hit CMD + SHIFT + P and the current file will be executed using Node

Francesco
~ 9 years ago

Thanks Shane, that in itself seems like a really cool little video tip. Awesome stuff :)

Tony Brown
~ 9 years ago

Hi Francesco

It's just https://www.jetbrains.com/webstorm/

Then I have a run configuration setup to a key binding, so at any point I can hit CMD + SHIFT + P and the current file will be executed using Node

Any chance you can tell us how to set that up? Looks very convenient

Alejandro Pereira
~ 8 years ago

Hello Shane, how could i use concat, but append items to the start of the array?

Abdullah
~ 5 years ago

@alejandropereira

You can apply the concat method to the array which should come first, and supply the other array as an argument. Example:

let arr = [[1, 2, 3]]

arr.concat([[4, 5, 6]]) // [[1, 2, 3, 4, 5, 6]]

[[4, 5, 6]].concat(arr) // [[4, 5, 6, 1, 2, 3]]

Hope that helps