Dùng replace() với regex /.+(.{3})$/ thay phần đầu bằng "**** " giữ 3 ký tự cuối.
Mã thực hiện
const hideDataWithDot = value => value.replace(/.+(.{3})$/, "**** $1");
console.log(hideDataWithDot('6778922'));
console.log(hideDataWithDot('76633 56 1443'));
console.log(hideDataWithDot('8888 4532 3232 9999'));
Kết quả
**** 922 **** 443 **** 999