Hàm xóa dấu tiếng Việt

mail@pastecode.io avatar
unknown
javascript
3 years ago
953 B
9
Indexable
function removeVietnameseAccents(str) {
    const AccentsMap = [
        'aàảãáạăằẳẵắặâầẩẫấậ',
        'AÀẢÃÁẠĂẰẲẴẮẶÂẦẨẪẤẬ',
        'dđ',
        'DĐ',
        'eèẻẽéẹêềểễếệ',
        'EÈẺẼÉẸÊỀỂỄẾỆ',
        'iìỉĩíị',
        'IÌỈĨÍỊ',
        'oòỏõóọôồổỗốộơờởỡớợ',
        'OÒỎÕÓỌÔỒỔỖỐỘƠỜỞỠỚỢ',
        'uùủũúụưừửữứự',
        'UÙỦŨÚỤƯỪỬỮỨỰ',
        'yỳỷỹýỵ',
        'YỲỶỸÝỴ',
    ];
    for (const accent of AccentsMap) {
        const re = new RegExp(`[${accent.substr(1)}]`, 'g');
        const char = accent[0];
        str = str.replace(re, char);
    }
    return str;
}


temp1.filter(x => removeVietnameseAccents(x['Tên tài liệu'] || '').toUpperCase().includes(removeVietnameseAccents('quy trinh').toUpperCase()))