๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป UnderScore

์ด์ „ ๊ธ€์—์„  Array์— ์“ฐ์ด๋Š” underscore๋ฅผ ์•Œ์•„๋ณด์•˜๊ณ ~ ๐Ÿ’๐Ÿปโ€๐Ÿ’๐Ÿปโ€๐Ÿ’๐Ÿปโ€
์ด๋ฒˆ์—” Object์— ์“ฐ์ด๋Š” underscore๋ฅผ ์•Œ์•„๋ด…์‹œ๋‹ค~! ๐Ÿ’๐Ÿ’๐Ÿ’


Object

_.keys(object)

object์˜ key๋ฅผ ๋ฐฐ์—ด๋กœ ๋ฆฌํ„ดํ•œ๋‹ค.

console.log(_.keys({one: 1, two: 2, three: 3})); // [ 'one', 'two', 'three' ]

_.values(object)

object์˜ value๋ฅผ ๋ฐฐ์—ด๋กœ ๋ฆฌํ„ดํ•œ๋‹ค

console.log(_.values({one: 1, two: 2, three: 3})); // [ 1, 2, 3 ]

_.mapObject(object, iteratee, [context])

๊ฐ์ฒด๋ฅผ ์œ„ํ•œ map

var res = _.mapObject({start: 5, end: 12}, function(val, key) {
  return val + 5;
});
console.log(res); // { start: 10, end: 17 }

_.pairs(object)

๊ฐ์ฒด๋ฅผ [key, value] ์Œ์˜ ๋ฐฐ์—ด๋กœ ๋ฆฌํ„ด

console.log(_.pairs({one: 1, two: 2, three: 3})); // [ [ 'one', 1 ], [ 'two', 2 ], [ 'three', 3 ] 

_.extend(destination, *sources)

sources๊ฐ์ฒด๋ฅผ destination์— ๋ณต์‚ฌ

console.log(_.extend({name: 'moe'}, {age: 50})); // { name: 'moe', age: 50 }

_.pick(object, *keys)

์„ ํƒํ•˜์—ฌ ํ•„ํ„ฐ๋งํ•œ๋‹ค.

console.log(_.pick({name: 'moe', age: 50, userid: 'moe1'}, 'name', 'age')); // { name: 'moe', age: 50 }
console.log(_.pick({name: 'moe', age: 50, userid: 'moe1'}, function(value, key, object) {
  return _.isNumber(value);
})); // { age: 50 }

_.has(object, key)

key๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ

console.log(_.has({a: 1, b: 2, c: 3}, "b")); // true