I have two array
array number 1:
let search = ['ا', 'ب', 'ج', 'د', 'ه','و', 'ز', 'ح', 'ط', 'ي','ك', 'ل', 'م', 'ن', 'س','ع', 'ف', 'ص', 'ق', 'ر','ش', 'ت', 'ث', 'خ', 'ذ','ظ', 'ض', 'غ'];
array number 2:
let replace = ['1', '2', '3', '4', '5','6', '7', '8', '9', '10','20', '30', '40', '50', '60','70', '80', '90', '100', '200','300', '400', '500', '600', '700','800', '900', '1000'];
and this is an input :
let word = "محمد";
I want in javascript search the letters of the variable word and replace them with the equivalent of number in the replace array .The replace array and the search array have the same numbers of letters and number.
The output will be:
م 40
ح 8
م 40
د 4
total = 92
let word = "محمد";
let search = ['ا', 'ب', 'ج', 'د', 'ه', 'و', 'ز', 'ح', 'ط', 'ي', 'ك', 'ل', 'م', 'ن', 'س', 'ع', 'ف', 'ص', 'ق', 'ر', 'ش', 'ت', 'ث', 'خ', 'ذ', 'ظ', 'ض', 'غ'];
let replace = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '20', '30', '40', '50', '60', '70', '80', '90', '100', '200', '300', '400', '500', '600', '700', '800', '900', '1000'];
if (word === "") {
document.write('the field is empty');
} else {
w = word.split("").filter(function(ele) {
return ele.replace(search, replace);
}).map(function(ele) {
return ele + ele;
});
}
console.log(w);