lodash duplicate array code example
Example 1: lodash find duplicate element index
const _ = require('lodash');
let arr = ["a", "a", "b", "c", "c", "a"];
let result = _.omitBy(
_.reduce(arr, (a, v, i) => _.set(a, v, (a[v] || []).concat([i])), {} ),
v => v.length <= 1
);
console.log(result);
Example 2: lodash map
const _quote_filter = _.map(quote_state, (val, key) => { if (val) { return key }})console.log(_quote_filter) //=> [ 'btc', undefined, undefined ]
Example 3: get lodash
var object = { 'a': [{ 'b': { 'c': 3 } }] }; _.get(object, 'a[0].b.c');// => 3 _.get(object, ['a', '0', 'b', 'c']);// => 3 _.get(object, 'a.b.c', 'default');// => 'default'