悉野小楼

导航

手机号脱敏

手机号脱敏
function maskPhoneNumber(phone: string): string {
    return phone.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2');
}

//arr.splice(3, 4, '****')​​:从数组的第3个位置(索引从0开始)开始,删除4个元素,并插入'****'
//split + splice + join
function maskPhoneNumber(phone: string): string {
    let arr = phone.split('');
    arr.splice(3, 4, '****');
    return arr.join('');
}

splice 拼接

    /**
     * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
     * @param start The zero-based location in the array from which to start removing elements.
     * @param deleteCount The number of elements to remove.
     * @returns An array containing the elements that were deleted.
     */
    splice(start: number, deleteCount?: number): T[];
    /**
     * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
     * @param start The zero-based location in the array from which to start removing elements.
     * @param deleteCount The number of elements to remove.
     * @param items Elements to insert into the array in place of the deleted elements.
     * @returns An array containing the elements that were deleted.
     */
    splice(start: number, deleteCount: number, ...items: T[]): T[];

posted on 2025-08-06 15:31  悉野  阅读(17)  评论(0)    收藏  举报