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

mail@pastecode.io avatar
unknown
javascript
2 years ago
953 B
5
Indexable
Never
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()))