How to wrap a string every 7 characters?

how do I wrap a string every 7 characters?

Jul.27,2021

var str='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
var result = str.replace(/(.{7})/g, '$1\n')

//
function _chunk(arr,size){
        let j = 0,o = j;
            let newArray = [];                     
            while(j < arr.length){
                j+=size;
                newArray.push([arr.slice(o,j)]);
                o = j;
            }
        return newArray;
}
_chunk("dafdafdfaffdasfafdfafdsfadasa",7).join('\n')

function sliceStr(str,len){
    let result = '';
    let sIndex = 0;
    let eIndex = len;
    while (str.length > sIndex) {
         result += str.slice(sIndex, eIndex) + '\n'
         sIndex += len;
         eIndex += len;
    }
    return result;
}

the answer to @ a2774206 simplifies

function newLine(str, size){
            var newArray = [];
            for (var i = 0,len = str.length; i < len; i += size) {
                newArray.push(str.slice(i, i + size));
            }
            return newArray.join('\n');
        }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5af89-442ac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5af89-442ac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?