Arabic with english letters indexing

Viewed 31

I have arabic string with some special signs:

const str = "- زيادة زمن التصويب تحت المنظار (+۱۰%)";

const arr = [];
for(let i=0;i<str.length;i++){
    arr.push(str[i]);
}
console.log(arr);

But the result of that is a messed up array of: ['-', ' ', 'ز', 'ي', 'ا', 'د', 'ة', ' ', 'ز', 'م', 'ن', ' ', 'ا', 'ل', 'ت', 'ص', 'و', 'ي', 'ب', ' ', 'ت', 'ح', 'ت', ' ', 'ا', 'ل', 'م', 'ن', 'ظ', 'ا', 'ر', ' ', '(', '+', '۱', '۰', '%', ')']

Any idea how to maintain the order of each sign?

1 Answers

When running this in the StackOverflow console, the display is correct and the array stores the characters correctly. Please see the below example.

It seems that your console wraps the output when displaying the content of the array. I think you then tried to join the lines together to produce one line output for the purpose of the question.

I think you had a console output like this in your console (example in VSCode console):

enter image description here

Try running your code again here:

const str = "- زيادة زمن التصويب تحت المنظار (+۱۰%)";

const arr = [];
for(let i=0;i<str.length;i++){
    arr.push(str[i]);
}
console.log(arr);

Please note that this Arabic text you provided is not stored as RTL but seems to be LTR as the last character "hyphen" should appear at the right of the text if it was in RTL format.

Related