wpLovr white logo
				
					/* The concat([new],...) method concatenates (joins) two or more arrays */

colors = [๐ŸŸฃ,๐ŸŸก];
colors.concat([๐ŸŸ ,๐ŸŸข]);

result:
    [๐ŸŸฃ,๐ŸŸก,๐ŸŸ ,๐ŸŸข]
				
			
				
					/* The slice(start, end) method returns selected elements in an array, as a new array. */

colors = [๐ŸŸฃ,๐ŸŸก,๐ŸŸ ,๐ŸŸข];
new = colors.slice(1,3);

result:
    [๐ŸŸก,๐ŸŸ ]
				
			
				
					/* The splice(start, delete, [new]) method adds and/or removes array elements from the original array */

//add
colors = [๐ŸŸฃ,๐ŸŸก,๐ŸŸ ,๐ŸŸข];
colors.splice(1,0,๐Ÿ”ต);


result:
    [๐ŸŸฃ,๐Ÿ”ต,๐ŸŸก,๐ŸŸ ,๐ŸŸข]


//remove
colors = [๐ŸŸฃ,๐ŸŸก,๐ŸŸ ,๐ŸŸข];
colors.splice(1,2);


result:
    [๐ŸŸฃ,๐ŸŸข]


//swap
colors = [๐ŸŸฃ,๐ŸŸก,๐ŸŸ ,๐ŸŸข];
colors.splice(1,2,๐Ÿ”ต,๐Ÿ”ด);


result:
    [๐ŸŸฃ,๐Ÿ”ต,๐Ÿ”ด,๐ŸŸข]
				
			
				
					/* The join(separator) method returns an array as a string and does not change the original array. */

colors = [๐Ÿ”ต,๐ŸŸก,๐ŸŸ ,๐ŸŸข];
string = colors.join('-');

result:  (string)
    '๐Ÿ”ต-๐ŸŸก-๐ŸŸ -๐ŸŸข'
				
			
				
					/* The pop() method removes (pops) the last element of an array changing the original array and returning what was removed. */

colors = [๐ŸŸฃ,๐Ÿ”ด,๐ŸŸข,๐Ÿ”ต];
string = colors.pop();

result: (colors)
    [๐ŸŸฃ,๐Ÿ”ด,๐ŸŸข]

return: (string)
    '๐Ÿ”ต'
				
			
				
					/* The shift() method removes the first item of an array, changes the original array and returning what was removed */

colors = [๐ŸŸฃ,๐Ÿ”ด,๐Ÿ”ต,๐ŸŸก];
string = colors.shift();

result: (colors)
    [๐Ÿ”ด,๐Ÿ”ต,๐ŸŸก]

return: (string)
    '๐ŸŸฃ'
				
			
				
					/* The push() method adds new items to the end of an array, changes the length of the original array and returns the new length */

colors = [๐Ÿ”ด,๐Ÿ”ต,๐ŸŸก];
colors.push(๐ŸŸข);

result: (colors)
    [๐Ÿ”ด,๐Ÿ”ต,๐ŸŸก,๐ŸŸข]

return: (length)
    4
				
			
				
					/* The unshift() method adds new elements to the beginning of an array, changes the original array and returns the new length */

colors = [๐ŸŸฃ,๐ŸŸก,๐ŸŸ ,๐Ÿ”ด];
colors.unshift(๐ŸŸข);

result (colors):
    [๐ŸŸข,๐ŸŸฃ,๐ŸŸก,๐ŸŸ ,๐Ÿ”ด]

return (length):
    5
				
			
				
					/* 7 ways to loop through an array in javascript */

// 1. for loop
colors = [๐ŸŸฃ,๐ŸŸก,๐ŸŸ ,๐Ÿ”ด];
let ( for i = 0; i < colors.length; i++ ){
    console.log(colors[i]);
}

result (colors):
    ๐ŸŸฃ
    ๐ŸŸก
    ๐ŸŸ 
    ๐Ÿ”ด


// 2. for...in loop
animals = [๐Ÿ“, ๐Ÿˆ, ๐Ÿ•, ๐Ÿฆ†, ๐Ÿฟ];
for ( let index in animals ){
    console.log(animals[index]);
}

result (animals):
    ๐Ÿ“
    ๐Ÿˆ
    ๐Ÿ•
    ๐Ÿฆ†
    ๐Ÿฟ


// 3. while loop
let cars = [๐Ÿš—, ๐Ÿš•, ๐Ÿš“, ๐Ÿš™];
let i = 0;
while ( i < cars.length){
    console.log(cars[i]);
    i++;
}

result (cars):
    ๐Ÿš—
    ๐Ÿš•
    ๐Ÿš“
    ๐Ÿš™


// 4. do...while loop
veggies = [๐Ÿ†,๐ŸŒถ,๐ŸŒฝ๏ธ];
let i = 0;
do {
    console.log(veggies[i]);
    i++;
} while (i < 5);

result (veggies):
    ๐Ÿ†
    ๐ŸŒถ
    ๐ŸŒฝ


// 5. for...of loop
tools = [๐Ÿชš,๐Ÿช“,๐Ÿ—œ,๐Ÿช›,๐Ÿ”จ];
for ( let value of tools ){
    console.log(value);
}

result (tools):
    ๐Ÿชš
    ๐Ÿช“
    ๐Ÿ—œ
    ๐Ÿช›
    ๐Ÿ”จ


// 6. forEach method
emotes = [๐Ÿ˜,๐Ÿ˜†,๐Ÿฅน,๐Ÿคฃ];
emotes.forEach((value)=>{
    console.log(value);
});

result (tools):
    ๐Ÿ˜
    ๐Ÿ˜†
    ๐Ÿฅน
    ๐Ÿคฃ


// 7. map() method
hats = [๐ŸŽฉ,๐Ÿ‘’,๐ŸŽ“,โ›‘,๐Ÿงข];
const newHats = hats.map((value) => {
    return value;
});
console.log(newHats);

result (newHats):
    [๐ŸŽฉ,๐Ÿ‘’,๐ŸŽ“,โ›‘,๐Ÿงข]