๐ฉ๐
20์ผ์ฐจ
Part 4. JavaScript Level up
Ch 1. JS ๋ฐ์ดํฐ
Ch 1. JS ๋ฐ์ดํฐ
์ฃผ์
- JS ๋ฌธ๋ฒ
์ฃผ์ ๋ด์ฉ
๐ ๋ฌธ์
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String
- string.prototype.indexOf(str): ์ฃผ์ด์ง ๊ฐ str๊ณผ ์ผ์นํ๋ ์ฒซ ๋ฒ์งธ ์ธ๋ฑ์ค ๋ฐํ
- string.prototype.slice(startIndex, endIndex): ์ธ๋ฑ์ค startIndex๋ถํฐ endIndex-1 ๊น์ง์ ๋ฌธ์์ด ๋ฐํ
- string.prototype.replace(str1, str2): ๋ฌธ์์ด str1์ str2๋ก ๋์ฒด
- string.prototype.match(): ์ ๊ทํํ์
- string.prototype.trim(): ๊ณต๋ฐฑ ์ ๊ฑฐ
๐ ์ซ์์ ์ํ
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Math
- parseInt() / parseFloat()
- Math.abs(x): ์ ๋๊ฐ ๋ฐํ
- Math.min(x, y): x, y ์ค ๊ฐ์ฅ ์์ ๊ฐ ๋ฐํ
- Math.max(x, y): x, y ์ค ๊ฐ์ฅ ํฐ ๊ฐ ๋ฐํ
- Math.ceil(x): ์ฌ๋ฆผ
- Math.floor(x): ๋ด๋ฆผ
- Math.round(x): ๋ฐ์ฌ๋ฆผ
- Math.random(): ๋๋ค ์ซ์ ๋ฐํ
๐ ๋ฐฐ์ด
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array
- Array.prototype.find(callback): ์ฃผ์ด์ง ํ๋ณ ํจ์๋ฅผ ๋ง์กฑํ๋ ์ฒซ ๋ฒ์งธ ์์์ ๊ฐ์ ๋ฐํ
- Array.prototype.concat(arr): ๋ฐฐ์ด ํฉ์น๊ธฐ (์๋ณธ ์ ์ง)
const numbers = [1, 2, 3, 4];
const fruits = ["Apple", "Banana", "Cherry"];
console.log(numbers.concat(fruits)); // ์๋ณธ ์ ์ง!
console.log(numbers);
console.log(fruits);
- Array.prototype.forEach(callback(item, index)): ๋ฐฐ์ด ๋ฐ์ดํฐ์ ์์ดํ ์ ๊ฐ์ ๋งํผ ํน์ ํ callback ํจ์๋ฅผ ๋ฐ๋ณต์ ์ผ๋ก ์คํ => ๋ฐ๋ก ๋ฐํ๋๋ ๊ฐ์ ์๋ค.
const numbers = [1, 2, 3, 4];
const fruits = ["Apple", "Banana", "Cherry"];
fruits.forEach(function (element, index, array) {
console.log(element, index, array);
});
- Arrow.prototype.map(callback(item, index)): callback ๋ด๋ถ์์ ๋ฐํํ๋ ๋ฐ์ดํฐ๋ฅผ ๋ชจ์ ๋์ ์๋ก์ด ๋ฐฐ์ด์ ๋ง๋ค์ด์ ๋ฐํ (์๋ณธ ์ ์ง)
const numbers = [1, 2, 3, 4];
const fruits = ["Apple", "Banana", "Cherry"];
const a = fruits.forEach((fruit, index) => {
console.log(`${fruit}-${index}`);
});
console.log(a);
const b = fruits.map((fruit, index) => ({
id: index,
name: fruit,
}));
console.log(b);
- Array.prototype.filter(callback(item, index)): ๋ฐฐ์ด ๋ฐ์ดํฐ ์์ ๋ค์ด ์๋ ๊ฐ๊ฐ์ ์์ดํ ๋ค์ ํน์ ํ ๊ธฐ์ค์ ์ํด์ ํํฐ๋ง, ํํฐ๋ ์๋ก์ด ๋ฐฐ์ด ๋ฐ์ดํฐ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํ (์๋ณธ ์ ์ง)
const numbers = [1, 2, 3, 4];
const fruits = ["Apple", "Banana", "Cherry"];
const a = numbers.map((number) => number < 3);
console.log(a);
const b = numbers.filter((number) => number < 3);
console.log(b);
console.log(numbers);
- Array.prototype.find(callback): callback ๋ด์์ ๋ญ๊ฐ๋ฅผ ์ฐพ์ผ๋ฉด ๋ฐ๋ณต์ด ์ข ๋ฃ๋๊ณ , ์ฐพ์์ง ๋ฐฐ์ด์ ์์ดํ ์ด ๋ฐํ
- Array.prototype.findIndex(callback): ์์ ์ธ๋ฑ์ค ๋ฒํธ๋ฅผ ๋ฐํ
const numbers = [1, 2, 3, 4];
const fruits = ["Apple", "Banana", "Cherry"];
const a = fruits.find((fruit) => /^B/.test(fruit));
console.log(a);
const b = fruits.findIndex((fruit) => /^B/.test(fruit));
console.log(b);
- Array.prototype.includes(item): ๋ฐฐ์ด์ item์ด ํฌํจ๋์ด ์๋์ง ์ฌ๋ถ ๋ฐํ
const numbers = [1, 2, 3, 4];
const fruits = ["Apple", "Banana", "Cherry"];
const a = numbers.includes(3);
console.log(a);
const b = fruits.includes("HEROPY");
console.log(b);
- Array.prototype.push(item): ๋ฐฐ์ด ๊ฐ์ฅ ๋ค์ item ์ฝ์ (์๋ณธ ์์ ๋จ ์ฃผ์)
- Array.prototype.unshift(item): ๋ฐฐ์ด ๊ฐ์ฅ ์์ item ์ฝ์ (์๋ณธ ์์ ๋จ ์ฃผ์)
const numbers = [1, 2, 3, 4];
const fruits = ["Apple", "Banana", "Cherry"];
numbers.push(5);
console.log(numbers);
numbers.unshift(0);
console.log(numbers);
- Array.prototype.reverse(): ๋ฐฐ์ด ์์ดํ ์์ ๋ค์ง๊ธฐ (์๋ณธ ์์ ๋จ ์ฃผ์)
const numbers = [1, 2, 3, 4];
const fruits = ["Apple", "Banana", "Cherry"];
numbers.reverse();
fruits.reverse();
console.log(numbers);
console.log(fruits);
- Array.prototype.splice(index, deleteCount, item1, item2 ...): index๋ถํฐ deleteCount ๋งํผ ์์ดํ ์ญ์ & ๊ทธ ์๋ฆฌ์ item1 ๋ผ์๋ฃ๊ธฐ (์๋ณธ ์์ ๋จ ์ฃผ์)
const numbers = [1, 2, 3, 4];
const fruits = ["Apple", "Banana", "Cherry"];
numbers.splice(2, 1, 99);
console.log(numbers);
fruits.splice(2, 0, "Orange");
console.log(fruits);
๋๋์
์ ๋ฆฌ ํ๋ค๋ค................
'๐ฌ > ใ ใ ใ ใ ใ ใ ์ฑ๋ฆฐ์ง' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
22์ผ์ฐจ (0) | 2022.02.25 |
---|---|
21์ผ์ฐจ (0) | 2022.02.20 |
ใ ใ ใ ใ ใ ใ ์ฑ๋ฆฐ์ง ์คํจํ๋์,,,,,,,,, ๋ฐํํ,,,,,,,,,,,,,,,, ๐๐คฃ๐ ๐ฅ๐๐ข๐ญ๐ฒ๐จ๐ฐ๐ฑ๐ฅถ๐ฆ๐ฆ๐ฆ (0) | 2022.02.13 |
ํจ์คํธ์บ ํผ์ค ์ฑ๋ฆฐ์ง 19์ผ์ฐจ (0) | 2022.02.11 |
ํจ์คํธ์บ ํผ์ค ์ฑ๋ฆฐ์ง 18์ผ์ฐจ (0) | 2022.02.10 |