When I tried splitting:
"بحد-8635".split('-')
then JavaScript gives me this result:
[0] - بحد, [1] - 8635
console.log("بحد-8635".split('-'))
And when I tried splitting:
"2132-سسس".split('-')
it gives me this different result:
[0] - 2132 [1] - سسس
console.log("2132-سسس".split('-'))
How is this happening? How can this be implemented correctly?
The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
separator: It is optional parameter. It defines the character or the regular expression to use for breaking the string. If not used, the same string is returned (single item array). limit: It is optional parameter.
Introduction. A string is a sequence of one or more characters that may consist of letters, numbers, or symbols. Each character in a JavaScript string can be accessed by an index number, and all strings have methods and properties available to them.
It depends on how you type the string (left to right / right to left). In the provided question, "2132-سسس" was typed from left to right and "8635-بحد" was typed from right to left.
Check the below snippet.
console.log("Typed left to right:"); console.log("2132-سسس".split('-')); console.log("8635-بحد".split('-')); console.log("---------------"); console.log("Typed right to left as Arabians follow:"); console.log("سسس-2132".split('-')); console.log("بحد-8635".split('-'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With