Building an Abjad Calculator in JavaScript

Complete JavaScript Example for Abjad System

The Abjad numeral system is an ancient method of assigning numerical values to the letters of the Arabic alphabet. Long before the widespread use of modern Arabic numerals, letters themselves were commonly used to represent numbers in historical documents, inscriptions, poetry, and Islamic manuscripts.

Today, the Abjad system continues to be used in several contexts, including:

  • Islamic studies
  • Arabic linguistics
  • Historical chronology
  • Digital humanities
  • Educational applications
  • Word analysis tools
  • Abjad calculators

From a developer’s perspective, building an Abjad calculator is a practical JavaScript exercise. It involves mapping characters to values, iterating through Unicode strings, and calculating a total using a simple lookup table.

In this article, you’ll build a lightweight Abjad calculator in JavaScript that you can immediately use in a browser or Node.js application. The implementation uses the traditional Mashriqi (Eastern) Abjad Kabir values, which are the standard used throughout most Arabic and Persian references.


How the Abjad System Works

salam abjad number

Every Arabic letter has a fixed numerical value.

The first nine letters represent the numbers 1 through 9.

The next group represents the tens.

The final group represents the hundreds.

The traditional sequence is:

Letter Value Letter Value
ا 1 ق 100
ب 2 ر 200
ج 3 ش 300
د 4 ت 400
ه 5 ث 500
و 6 خ 600
ز 7 ذ 700
ح 8 ض 800
ط 9 ظ 900
ي 10 غ 1000
ك 20
ل 30
م 40
ن 50
س 60
ع 70
ف 80
ص 90

Calculating the value of a word is simply a matter of adding together the values of its individual letters.

For example, the word:

سلام

is calculated as:

Letter Value
س 60
ل 30
ا 1
م 40

Total:

60+30+1+40 = 131

Once you understand this simple rule, implementing it in JavaScript becomes straightforward.


Creating the Letter Mapping

Abjad values table Mashriqi

The easiest way to store Abjad values is with a JavaScript object.

Each Arabic letter becomes a property, and its Abjad value becomes the corresponding value.

const ABJAD = {
    // 1 - 9
    "ا": 1,
    "ب": 2,
    "ج": 3,
    "د": 4,
    "ه": 5,
    "و": 6,
    "ز": 7,
    "ح": 8,
    "ط": 9,
    // 10 - 90
    "ي": 10,
    "ك": 20,
    "ل": 30,
    "م": 40,
    "ن": 50,
    "س": 60,
    "ع": 70,
    "ف": 80,
    "ص": 90,
    // 100 - 1000
    "ق": 100,
    "ر": 200,
    "ش": 300,
    "ت": 400,
    "ث": 500,
    "خ": 600,
    "ذ": 700,
    "ض": 800,
    "ظ": 900,
    "غ": 1000
};

Using an object gives us constant-time lookups (O(1)), making this approach efficient even for longer strings.


Writing the Calculator Function

Now that the mapping is available, the calculator itself only needs to:

  1. Loop through every character.
  2. Find its value.
  3. Add the value to a running total.
  4. Return the final result.
function calculateAbjad(text) {
    let total = 0;
    for (const letter of text) {
        if (ABJAD[letter]) {
            total += ABJAD[letter];
        }
    }
    return total;
}

The function ignores any character that doesn’t exist in the mapping. That means spaces, punctuation, and unsupported symbols won’t cause errors.


Complete JavaScript Example

Complete JavaScript Example for Abjad System

The following example is a complete implementation that can be copied directly into your own project.

const ABJAD = {
    // 1 - 9
    "ا": 1,
    "ب": 2,
    "ج": 3,
    "د": 4,
    "ه": 5,
    "و": 6,
    "ز": 7,
    "ح": 8,
    "ط": 9,
    // 10 - 90
    "ي": 10,
    "ك": 20,
    "ل": 30,
    "م": 40,
    "ن": 50,
    "س": 60,
    "ع": 70,
    "ف": 80,
    "ص": 90,
    // 100 - 1000
    "ق": 100,
    "ر": 200,
    "ش": 300,
    "ت": 400,
    "ث": 500,
    "خ": 600,
    "ذ": 700,
    "ض": 800,
    "ظ": 900,
    "غ": 1000
};

function calculateAbjad(text) {
    let total = 0;
    for (const letter of text) {
        if (ABJAD[letter]) {
            total += ABJAD[letter];
        }
    }
    return total;
}

// Examples
console.log(calculateAbjad("الله"));
console.log(calculateAbjad("محمد"));
console.log(calculateAbjad("سلام"));
console.log(calculateAbjad("نور"));

That’s all you need to build a working Abjad calculator.

In the next section, we’ll see what output this code produces and how you can integrate it into a real project.

Share this