๐ŸŸจ 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..