๐จ JavaScript
๊ฐ์ฅ ์ต์ ์ jquery ๋งํฌ
script src="http://code.jquery.com/jquery-latest.min.js">script>
[๋๋ฆผ์ฝ๋ฉ] ์ ์ฉํ ๋ฐฐ์ด(array) api (3) : reduce, reduceRight, sort, api ๋ค์ค์ผ๋ก ์ฐ๊ธฐ
class Coder { constructor(name, age, enrolled, score) { this.name = name; this.age = age; this.enrolled = enrolled; this.score = score; } } const coders = [ new Coder('A', 29, true, 45), new Coder('B', 28, false, 80), new Coder('C', 30, true, 90), new Coder('D', 40, false, 66), new Coder('E', 18, true, 88), ] reduce ๋ฐฐ์ด์ ๊ฐ ๋ฐ์ดํฐ์ ์ฃผ์ด์ง ๋ฆฌ๋์(reducer)ํจ์๋ฅผ ์คํํ๊ณ , ํ๋์ ๊ฒฐ๊ณผ๊ฐ์ ๋ฐํํ๋ค. ๋ฆฌ๋์ ์ฝ๋ฐฑํจ์๋ ๋ค ๊ฐ์ ์ธ์๋ฅผ ๊ฐ์ง๋ค. ๋์ฐ๊ธฐ(..
[๋๋ฆผ์ฝ๋ฉ] ์ ์ฉํ ๋ฐฐ์ด(array) api (2) : filter, map, some, every
class Coder { constructor(name, age, enrolled, score) { this.name = name; this.age = age; this.enrolled = enrolled; this.score = score; } } const coders = [ new Coder('A', 29, true, 45), new Coder('B', 28, false, 80), new Coder('C', 30, true, 90), new Coder('D', 40, false, 66), new Coder('E', 18, true, 88), ] filter enrolled๊ฐ true์ธ ์ฝ๋๋ง ๊ณจ๋ผ ์๋ก์ด ๋ฐฐ์ด์ ๋ง๋ค์ด๋ณด์. const result = coders.filter((coder) => co..
[๋๋ฆผ์ฝ๋ฉ] ์ ์ฉํ ๋ฐฐ์ด(array) api (1) : join, split, reverse, slice, find
join ๋ฐฐ์ด์ ๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ string์ผ๋ก ํฉ์ณ ๋ณํํ๋ค. const goodcoders = ['noran', 'paran', 'black', 'white']; const result = goodcoders.join(); console.log(result); //noran,paran,black,white ์ฐธ๊ณ ์๋์ฒ๋ผ ๊ตฌ๋ถ์๋ฅผ ์ ๋ฌํ๋ฉด ์ ๋ฌ๋ ๊ตฌ๋ถ์๋ก ๊ตฌ๋ถ๋์ด ๋ํ๋๋ค. const result = goodcoders.join(|); console.log(result); //noran|paran|black|white split string ๋ฐ์ดํฐ๋ฅผ ๋ฐฐ์ด๋ก ๋ง๋ ๋ค. const coders = 'noran,paran,black,white'; const result = coders.split(','); co..
[mdn, ๋๋ฆผ์ฝ๋ฉ ์ธ] ๋ฐฐ์ด(array) (4) : ๊ฒ์ (indexOf,lastIndexOf,includes)
๋ฐฐ์ด์ ๋ง๋ค์๋ค. const goodcoders = ['noran', 'paran', 'black', 'white', 'noran']; ๊ฒ์ indexOf : ๋ฐ์ดํฐ์ ์ธ๋ฑ์ค ์ฐพ๊ธฐ console.log(goodcoders.indexOf('paran')) //1 ์๋์ฒ๋ผ ๋ฐฐ์ด์ ์กด์ฌํ์ง ์๋ ๋ฐ์ดํฐ์ ์ธ๋ฑ์ค๋ฅผ ์ฐพ์ผ๋ฉด -1๋ก ๋ฌ๋ค. console.log(goodcoders.indexOf('green')) //-1 ์๋์ฒ๋ผ ๋ฐฐ์ด์ ์ค๋ณต์ผ๋ก ์กด์ฌํ๋ ๋ฐ์ดํฐ์ ์ธ๋ฑ์ค๋ฅผ ์ฐพ์ผ๋ฉด ์ฒซ๋ฒ์งธ ๋ฐ์ดํฐ์ ์ธ๋ฑ์ค๋ก ๋ฌ๋ค. console.log(goodcoders.indexOf('noran')) //0 lastIndexOf : (์ค๋ณต๋๋ ๋ฐ์ดํฐ์ ๊ฒฝ์ฐ) ๋ง์ง๋ง ๋ฐ์ดํฐ์ ์ธ๋ฑ์ค ์ฐพ๊ธฐ ๋ฐฐ์ด์ ์ค๋ณต์ผ๋ก ์กด์ฌํ๋ ๋ฐ์ดํฐ์ ์ธ๋ฑ์ค๋ฅผ ์ฐพ์ผ..
[mdn, ๋๋ฆผ์ฝ๋ฉ ์ธ] ๋ฐฐ์ด(array) (3) : ์ํ๋ ์์๋ถํฐ ์ถ๊ฐ/์ญ์ , ํฉ์น๊ธฐ (splice,concat)
๋ฐฐ์ด์ ๋ง๋ค์๋ค. const goodcoders = ['noran', 'paran', 'black','white']; const badcoders = ['green', 'blue']; splice : ์ํ๋ ์์์์ ์ํ๋ ๋งํผ ์ญ์ ํ๊ธฐ/๊ทธ ์๋ฆฌ์ ์ถ๊ฐํ๊ธฐ goodcoders.splice(2, 1); //(์ํ๋ ์์๋ถํฐ ์์,์ง์ฐ๊ณ ์ํ๋ ๊ฐ์) console.log(goodcoders); //'noran', 'paran', 'white' goodcoders.splice(2, 1, 'yellow', 'purple'); //(์ํ๋ ์์๋ถํฐ ์์,์ง์ฐ๊ณ ์ํ๋ ๊ฐ์, ์ถ๊ฐํ ๋ฐ์ดํฐ) console.log(goodcoders); //'noran', 'paran', 'yellow', 'purple', 'whit..