๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋ชฉ๋ก์ด ์—†์Šต๋‹ˆ๋‹ค.

[Javascript] Object์˜ key ๋ชฉ๋ก ๋‚˜์—ดํ•˜๊ธฐ

๐Ÿ—ฃ Language

    AngularJS์—์„œ custom filter๋ฅผ ๋งŒ๋“ค์–ด ๋ณด๊ณ  ์žˆ๋Š”๋ฐ ํŒŒ๋ผ๋ฏธํ„ฐ ๊ฐ’์œผ๋กœ object(๊ฐ์ฒด) ํ˜•์‹์„ ๋„˜๊ฒผ์Šต๋‹ˆ๋‹ค. ๊ทผ๋ฐ filter์•ˆ์—์„œ ๋ฐ›๊ณ  ๋ณด๋‹ˆ๊นŒ ์˜ค๋ธŒ์ ํŠธ ์•ˆ์— ์–ด๋–ค ํ‚ค๊ฐ€ ์žˆ๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ์–ด์„œ ์–ด๋–ป๊ฒŒํ•˜๋ฉด ํ‚ค ๊ฐ’์„ ๋ฝ‘์•„๋‚ด์„œ ๊ทธ ํ‚ค๊ฐ’์„ ํ†ตํ•ด ๋˜ ๋™์ผํ•œ ํ˜•ํƒœ์˜ ๊ฐ์ฒด์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์„๊นŒ๋ฅผ ๊ณ ๋ฏผํ•˜๋‹ค ๋ณด๋‹ˆ Javascript์— ์ด๋ฏธ ์žˆ๋Š”๊ฑธ ์•Œ๊ณ  ์ด๋ ‡๊ฒŒ ์ •๋ฆฌํ•ด๋ด…๋‹ˆ๋‹ค.






    ๋ฌธ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.


    var obj = {
        "key1" : "value1",
        "key2" : "value2"
    }
     
    var keys = Object.keys(obj);
     
    console.log(keys);
     
    for ( var i in keys ) {
        console.log(keys[i] + " : " + obj[keys[i]]); 
    }
    


    [์‹คํ–‰๊ฒฐ๊ณผ]

    [ 'key1', 'key2' ]

    key1 : value1

    key2 : value2