Some of my friends are reluctant to use https://lodash.com/ . They say lodash is heavy. That's why I create this library. This lodashget is light, it only contains small block of code that imitates lodash.get
.
const lodashget = require('@rizkisunaryo/lodashget')
const obj = {
a: {
b: 'c'
}
}
console.log(lodashget(obj, 'a.b')) // output: 'c'
const lodashget = require('@rizkisunaryo/lodashget')
const obj = {
a: {
b: 'c'
}
}
console.log(lodashget(obj, 'a.b.c', '')) // output: ''
const lodashget = require('@rizkisunaryo/lodashget')
const arr = [[1, [2, 3]], 4]
console.log(lodashget(arr, '[0][1][1]')) // output: 3
const lodashget = require('@rizkisunaryo/lodashget')
const obj = {
a: {
b: [1, [2, 3, {coba: 'saja'}], 5]
}
}
console.log(lodashget(obj, `a.b[1][2]['coba']`)) // output: 'saja'
const lodashget = require('@rizkisunaryo/lodashget')
const arr = [[1, [2, 3]], 4]
console.log(lodashget(arr, '[0][1][1].coba.saja', 10)) // output: 10
const lodashget = require('@rizkisunaryo/lodashget')
const obj = {
a: {
b: [1, [2, 3, {coba: 'saja'}], 5]
}
}
console.log(lodashget(obj, `a.b[1][2]['coba']['lagi']['terus']`, 'dasar')) // output: 'dasar'