- getCustomizedObject
/**
* @number: the count of object attribute
* @prefix: the object attribute prefix string
* @value: the value of each attribute, default is ''
* @start: the default start is 1
* Example:
* getCustomizedObject(3, 'amount') // {amount1:'', amount2:'', amount3:''}
*/
export const getCustomizedObject = (number, prefix, value='', start=1) => {
const keys = _.times(number, (i)=> `${prefix}${i+start}`);
const values = _.times(number, ()=> value);
return _.zipObject(keys, values);
};
- getCustomizedArray
/**
* @number: the elment count of array
* @prefix: the element value prefix string
* @start: the default start is 1
* Example:
* getCustomizedArray(3, 'amount', 2) // ['amount2', 'amount3', 'amount4']
*/
export const getCustomizedArray = (number, prefix, start=1) => {
return _.times(number, (i) => `${prefix}${i+start}`);
};
标签:const,lodash,_.,number,value,实用,start,prefix,函数
From: https://www.cnblogs.com/xiaodi-js/p/17129379.html