ckinmind / WebHub

📦前端资源/学习/问题整理中心,请看issue
109 stars 6 forks source link

lodash方法长期整理 #116

Open ckinmind opened 7 years ago

ckinmind commented 7 years ago

参考资料

清单

ckinmind commented 5 years ago

1._.trim()清理前后空格或指定字符

_.trim('   abc  ')
// => abc
ckinmind commented 5 years ago

2._.get()根据 object对象的path路径获取值

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'
ckinmind commented 5 years ago

3. _. uniqueId() 生成唯一ID

_.uniqueId('contact_');
// => 'contact_104'

_.uniqueId();
// => '105'