_lodash.js
文檔:https://www.lodashjs.com/docs/4.17.5.html
_.compact(array)
創建一個移除了所有假值的數組
什么是假值?false,null,0,"",undefined,NaN
_.compact([0, 1, false, 2, '', 3]); // => [1, 2, 3]
_.concat(array, [values])
創建一個用任何數組或值連接的新數組
var array = [1]; var other = _.concat(array, 2, [3], [[4]]); console.log(other); // => [1, 2, 3, [4]] console.log(array); // => [1]
_.indexOf(array, value, [fromIndex=0])
返回數組中首次匹配的index
_.indexOf([1, 2, 1, 2], 2); // => 1 _.indexOf([1, 2, 1, 2], 2, 2); // => 3
_.join(array, [separator=','])
將數組中的所有元素轉換為由separator分隔的字符串
_.join(['a', 'b', 'c'], '~'); // => 'a~b~c'
_.forEach(collection, [iteratee=_.identity])
遍歷集合
_([1, 2]).forEach(function(value){ console.log(value); }); // => 輸出 '1' 和 '2' _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { console.log(key); }); // => 輸出 'a' 和 'b' (不保證遍歷得順序)
(未完)
