Here, we will learn about the concat method for arrays in JavaScript. This method allows us to merge two or more arrays together.
0:00 Introduction to concat
0:12 Setting up two arrays
0:36 Merging two arrays using concat
1:26 Reversing the order
1:46 Using concat() with an empty array [].concat()
2:42 Writing a function that merges arrays using concat()
5:10 Using the forEach method to loop through our new array
6:07 Copying an array using concat()
8:17 Merging two arrays of objects using concat()
9:43 Using the forEach method to loop through our new array
Last Example:
class Items {
constructor(item, price, stock) {
this.item = item;
this.price = price;
this.stock = stock;
}
description() {
return `${this.item} costs $${this.price}. We currently have ${this.stock} in our store.`;
}
}
const groceryItems = [
new Items("Bread", 3, 30),
new Items("Milk", 4, 50),
new Items("Steak", 5, 10),
new Items("Rice", 1, 100),
];
const generalItems = [
new Items("Broom", 10, 3),
new Items("Microwave", 50, 2),
new Items("TV", 1000, 1),
new Items("Paper", 2, 300),
];
JavaScript Playlist:
• JavaScript for Beginners
MDN concat() Method:
https://developer.mozilla.org/en-US/d...
MDN forEach() Method:
https://developer.mozilla.org/en-US/d...
MDN Classes:
https://developer.mozilla.org/en-US/d...
NodeJS:
nodejs.org
VS Code:
code.visualstudio.com
Watch video JavaScript for Beginners #52 The concat() Array Method online without registration, duration hours minute second in high quality. This video was added by user GreeneMath.com 12 March 2021, don't forget to share it with your friends and acquaintances, it has been viewed on our site 663 once and liked it 16 people.