Object
//Object.keys()
var arr = ["a","b","c"];
//๋ฐฐ์ด์์ key๋ index์ด๋ฏ๋ก ๋ฐฐ์ด์ index๋ฅผ ๋ฐฐ์ด๋ก ๋ง๋ค์ด์ ๋ฆฌํดํ๋ค.
console.log('Object.keys(arr)', Object.keys(arr));//will alert "0,1,2"
//Object.prototype.toString()
var o = new Object();//๊ฐ์ฒด๋ฅผ ์์ฑํ์ฌ o์ ํ ๋นํ๋ค.>Object๋ ์์ฑ์ ํจ์๋ผ๋ ๊ฒ์ด๋ค.
console.log('o.toString()', o.toString());
var a = new Array(1,2,3);
console.log('a.toString()', a.toString());
Object.prototype.contain = function(needle){//๋ชจ๋ ๊ฐ์ฒด์ ๋ถ๋ชจObject์ ๋ฉ์๋๋ฅผ ๋ง๋ ๋ค.
for(var name in this) {//๋ฉ์๋ ์์์ this๋ ๋ฉ์๋๊ฐ ์์๋ ๊ฐ์ฒด!
//name์๋ ๊ฐ๊ฐ์ key๊ฐ์ด ๋ด๊ธฐ๊ฒ ๋๋ค.๋ง์น index์ฒ๋ผ ์ฌ์ฉ๋๋ค.
if(this[name] === needle){
return true;
}
}//๋๊น์ง ๋ค ๋์๋๋ฐ ์์ผ๋ฉด false๋ฅผ ๋ฆฌํด.
return false;
}
var o = {'name':'egoing','city':'seoul'}
console.log(o.contain('egoing'));Last updated