Javascript -- How to find and replace text matched via nested array list?

Viewed 911

I am trying to find text in all <p> tags, in document and replace the text if it is present in my search_array list:

search_array=[
                ['DBCONERROR01','Unable to Connect Database Server'],
                ['DBCONERROR02','Error Occured With DataBase Connection'],
                ['DBCONERROR03','Unable to Communicate with Data Base'],
                ['DBQRYERROR01','Invalid Query OR DataBase Error'],
                ['DBCONERROR04','Connection Lost with Database'],
                ['DBQRYERROR02','DataBase Query Failed'],
                ['DBQRYERROR03','Invalid to Wrong Sql Query'],
                ['TARIFERROR01','No Rates Found for Tariff'],
                ['AUTHSERROR01','Authentications not Found'],
                ['SWICHERROR01','Unable to Find Switch Details'],
                ['IOPRMERROR01','File Permission Error'],
                ['IOPRMERROR01','IO Error with operation System'],
                ['IOPRMERROR01','File Handling Error - Unable to Communicate with IO'],
                ['OPSSHERROR01','Unable to SSH switch - Connection Error'],
                ['OPSSHERROR02','SSH to Switch Failed'],
                ['OPSSHERROR03','Unable to Copy Scripts to Switch'],
                ['OPSSHERROR04','Unable to Execute Script on Switch'],
                ['JSONPERROR01','Unable to Parse Json'],
                ['TARIFERROR02','No Entry Found'],
                ['TARIFERROR03','Unable to Push Rates TO SBC'],
                ["DoesNotExist('Email does not exist.',)",'No Emails Received']
            ]
        $( document ).ready(function() {
            for(var i=0; i<search_array.length+1; i++)
                {
                    console.log(i);
                    console.log(search_array.length);
                    for(var j=0; j<search_array[i].length; j++)
                    {
                        var str = $("p").text();
                        console.log(str[0]);
                        str.replace(search_array[j], search_array[j+1]);
                    }
                }
            });

This is what my code looks like, But I am still unable to perform task... Kindly help me.

2 Answers
Related