
์ฌ๋ฌ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ด์ ๋ 100๊ฐ์ ๋ฐ์ดํฐ๊ฐ ์๋ค๊ณ ๊ฐ์ ํ๋ฉด ์ด 100๊ฐ์ ๋ฐ์ดํฐ ๋ณ์๋ฅผ ์ง์ ํด ์ค ๊ฒ์ด๋? ์๋๋ค, ํ๋์ ๋ณ์๋ก ์ฌ๋ฌ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ด์ ๋ ์ฐ๋ ๊ฒ์ด ๋ฐ๋ก ๋ฐฐ์ด์ด๋ค. ๋ฐฐ์ด์ ๊ด๋ จ ์๋ ๋ฐ์ดํฐ๋ค์ ํ๋๋ก ๋ฌถ์ด์ ํ๋์ ๋ณ์ ์๋์ ์ ์ฅํ๋ ๊ฒ์ด๋ค.

๊ทธ๋ฆผ๊ณผ ๊ฐ์ด num์ด๋ผ๋ ๋ฐฐ์ด๋ช
์ ์ง์ ํด์ฃผ๊ณ ์์ดํ
์ ๋ฐฐ์ดํ๋ค. ๊ทธ ์์ดํ
์ ๋ฒํธ๊ฐ ์ง์ ๋๋๋ฐ ๊ทธ ๋ฒํธ๋ฅผ ์ธ๋ฑ์ค๋ผ๊ณ ํ๊ณ ์ธ๋ฑ์ค๋ 0๋ถํฐ ์์ํ๋ค.
let fruit = ["banana", "apple", "mango","grape"];
console.log(fruit);
console.log(fruit[0]); // 0๋ฒ์งธ์ ์๋ ๊ฒ์ ์ถ๋ ฅํ๋ค. banana
fruit์ด๋ผ๋ ๋ฐฐ์ด๋ช ์ ์ง์ ํด์ฃผ๊ณ ๊ทธ ๋ฐฐ์ด์์ ์์ดํ ์ ์ง์ ํด ์ฃผ๋ ๊ฒ์ด๋ค.
console.log๋ ๊ฒฐ๊ณผ๊ฐ์ ์ถ๋ ฅํ๋ ๊ฒ์ด๋ค. console.log(fruit); ์ ๊ฒฐ๊ณผ๊ฐ์
['banana', 'apple', 'mango', 'grape'] ๋์จ๋ค.
console.log(fruit);์ ๊ฒฐ๊ณผ ๊ฐ์ banana ๊ฐ ๋์จ๋ค.
์ฌ๊ธฐ์ ๋ง์ฝ banana๋ฅผ cherry๋ก grape๋ฅผ tomato ๋ฐ๊พธ๊ณ ์ถ๋ค๋ฉด,
fruit[0] = "cherry";
console.log(fruit);
fruit[3] = "tomato";
console.log(fruit);
์์ ๊ฐ์ด ์ฝ๋๋ฅผ ์์ฑํ๋ค. banana์ ์ธ๋ฑ์ค๋ 0๋ฒ ์ธ๋ฑ์ค์ด๊ณ grape๋ 3๋ฒ ์ธ๋ฑ์ค์ด๋ค. 0๋ฒ ์ธ๋ฑ์ค์ cherry๋ผ๊ณ ํ ๋นํด์ฃผ๊ณ 3๋ฒ ์ธ๋ฑ์ค์ tomato์ ํ ๋นํด์ฃผ์ด ์ถ๋ ฅํ๋ฉด ๋์ค๋ ๊ฒฐ๊ณผ๊ฐ์ ['cherry', 'apple', 'mango', 'cherry'] ๋ผ๊ณ ๋์ค๋ ๊ฒ์ ์ ์ ์๋ค.
fruit.pop();
console.log(fruit);
์์ ๊ฐ์ด ์ฝ๋๋ฅผ ์์ฑ ํ๋ค. ๊ทธ๋ผ ๊ฒฐ๊ณผ ๊ฐ์ ['cherry', 'apple', 'mango'] ๊ฐ ๋์ค๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
๋ง์ง๋ง์ ์๋ ์์ดํ
์ ์ ๊ฑฐํ ๊ฒฐ๊ณผ๊ฐ์ด๋ค.
fruit.push("pineapple");
console.log(fruit);
๊ฒฐ๊ณผ ๊ฐ์ ['cherry', 'apple', 'mango', 'pineapple'] ์ด ๋์ค๋ ๊ฒ์ ๋ณผ ์ ์๋ค. ๋ฐฐ์ด ๋์ ์์ดํ ์ด ์ถ๊ฐ๋์ด ์๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
console.log(fruit.includes("apple"));
์ ๊ฐ์ ์ฝ๋๋ furit๋ผ๋ ๋ฐฐ์ด์ apple์ด ํฌํจ๋์ด ์๋?๋ฅผ ๋ฌผ์ด๋ณด๋ ๊ฒ์ด๋ค.
๊ฒฐ๊ณผ๊ฐ์ true ์ด๋ค. apple์ด ํฌํจ๋์ด ์์ผ๋ ๋น์ฐํ ๊ฒฐ๊ณผ ์ด๋ค.
console.log(fruit.indexOf("apple"));
๊ฒฐ๊ณผ ๊ฐ์ 1์ด๋ค. ๋ฐฐ์ด์ apple์ 1๋ฒ ์ธ๋ฑ์ค ๋ฒํธ๋ก ์ง์ ๋์ด ์์ด ๋์จ ๊ฒฐ๊ณผ์ด๋ค.
console.log(fruit.slice(1,3));
๊ฒฐ๊ณผ ๊ฐ์ ['apple', 'mango'] ์ด๋ค. ์ ์์์ ์ 1๋ก ๋์ ์ 3์ผ๋ก ์ธ๋ฑ์ค๋ฅผ ์คฌ๋๋ฐ ๊ฒฐ๊ณผ ๊ฐ์ด pineapple์ด ์๋๋ผ mango ๋๋ฉด ์์์ ๋์ ์ ํฌํจํ์ง ์์์ ์ด๋ค.
โ slice ํจ์๋
console.log(fruit);๋ก ์ถ๋ ฅ๋ชปํ๋์?
slice ํจ์๋ ๊ธฐ์กด์ ๋ฐฐ์ด์ ๊ฑด๋ค์ด์ง ์๊ณ ์๋ก์ด ๋ฐฐ์ด์ ๋ง๋ค์ด ๋ด๋ ๊ฒ์ด๋ฏ๋ก ์์ ๊ฐ์ด ์ถ๋ ฅ์ ์ํ๋ฉด ์๋ก์ด ๋ณ์๋ฅผ ์ ์ธํด ๊ทธ ์์ ํ ๋น์ ํด์ผํ๋ค. ์๋ฅผ ๋ค์ด ์ด๋ ๊ฒ๋คlet fruit let sub_fruit = fruit.slice(1,3); console.log(sub_fruit);์์ ๊ฐ์ด ์์ฑํ๋ฉด ๋๋ค.
fruit.splice(2,2); //(์์์ , ๊ฐ์)
console.log(fruit)
๊ฒฐ๊ณผ๊ฐ์ ['cherry', 'apple'] ์ด๋ค.
์์์ ์ธ ์ธ๋ฑ์ค 2์์ 2๊ฐ๋งํผ ์ ๊ฑฐํ ๊ฒ์ด๋ค.
๋ฐฐ์ด์ ํจ์๋ ์๋์ง๋ง ๋ฐฐ์ด์ ํฌ๊ธฐ๋ฅผ ๋ฆฌํดํด์ฃผ๋ ์์ฑ
let array = ["apple","banana","mango"]
console.log(array.length)
๊ฒฐ๊ณผ๊ฐ์ 3 ์ด๋ค. ๋ฐฐ์ด์ ์์ดํ ์ด ์ด 3๊ฐ๋ผ์ ๋์จ ๊ฐ์ด๋ค.
ํฌ์คํธ ์ ๋ดค์ต๋๋ค :) ํฝ ๊ณผ์ผ์ด ๋จน๊ณ ์ถ์ด์ง๋ ๊ธ์ ๋๋ค. ๐๐ฅญ๐๐๐๐