JS ⟩ objects ⟩ Array ⟩ methods ⟩ padEndSpaces()
💾 replit: arr.padEndSpaces()
// 🔸 arr.padEndSpaces(n)
/**
* pad spaces ("") to the end of array
*
* @example
*
* const a = ['班級','座號','姓名'];
* a.padEndSpaces(3), // [ '班級', '座號', '姓名', '', '', '' ]
*
*/
Array.prototype.padEndSpaces = function(n) {
return this.concat(Array(n).fill(''));
};
💈範例:
const a = ['班級','座號','姓名'];
a.padEndSpaces(3), // [ '班級', '座號', '姓名', '', '', '' ]