๐Ÿ’พarr.padEndSpaces()

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),        // [ '็ญ็ดš', 'ๅบง่™Ÿ', 'ๅง“ๅ', '', '', '' ]

Last updated

Was this helpful?