- Splice method: mute the original array
- Slice method: doesn't mute original array create new one
- Reverse method: mute original array
- Concat method: doesn't mute original array
- Join method:
- forEach: higher order function
const movements = [200, 450, -400, 3000, -650, -130, 70, 1300];
movements.forEach(function (movement) {
if (movement > 0) {
console.log(`You deposited ${movement}`);
} else {
console.log(`You withdrew ${Math.abs(movement)}`);
}
});
movements.forEach(function (movement, index, array) {}
- first parameter the current element , second parameter always the current index of array, third one always the entire array
- insertAdjacentHTML
element.insertAdjacentHTML(position, text);
- map returns a new array containing the result of applying an operation on all original array elements.
- filter returns a new array containing the array elements that passed a specified test condition.
- reduce boils ("reduces") all array elements down to one single value (e.g. adding all elements together)
- first parameter call accumulator . | like SNOWBALL| 2nd parameter current value .
return < 0, A, B, C (keep order)| return > 0, C, B, A (switch order)
- String and number together it's not work
// Ascending
movements.sort((a, b) => {
if (a > b) return 1;
if (a < b) return -1;
});
// or
movements.sort((a, b) => a - b);
// Descending
movements.sort((a, b) => {
if (a > b) return -1;
if (a < b) return 1;
});
// or
movements.sort((a, b) => b - a);
const y = Array.from({ length: 7 }, () => 1);
const z = Array.from({ length: 100 }, (_, i) => i++);
- Conversion
console.log(+'23');
type coercion. | convert into number
console.log(Number.parseInt('30px', 10));
console.log(Number.parseInt('e23', 10));
console.log(Number.isFinite(20));
console.log(Number.isFinite('20'));
console.log(new Date(account1.movementsDates[0]));
console.log(new Date(0));
console.log(new Data(3 * 24 * 60 * 60 * 1000));
// working with date
const future = new Date(2037, 10, 19, 15, 23);
console.log(future);
console.log(future.getFullYear()); | never use .getYear
console.log(future.getMonth());
console.log(future.getDate());
console.log(future.getDay());
console.log(future.getHours());
console.log(future.getMinutes());
console.log(future.getSeconds());
console.log(future.toISOString()); | international
console.log(future.getTime());
console.log(Date.now());
future.setFullYear(2040);
console.log(future);