I am trying to build an object, that takes in any value (preferrably an int) as the key, which generates the value for the key using a function, that has a dictionary for mapping out each individual digit to a digit of another language. Basically, I am passing a number in English as the key, and want to retrieve it's corresponding value of a different language.
For example, let there be an object numbers, whose only key will be dynamic, and that key will be transformed using a function to generate the value for that key in the object.
numbers = {
[number]: convertNumber(number)
}
const convertNumber = (number) => {
let dict = {
1: '١',
2: '٢',
3: '٣',
4: '٤',
5: '٥',
6: '٦',
7: '٧',
8: '٨',
9: '٩'
}
let newNumber = '';
number.toString().forEach(digit => {
newNumber = newNumber+dict[digit];
});
return newNumber;
}
Expected Output: numbers[1234] = '١٢٣٤';
But this code does not work, and I searched online for variable key names but did not find a way to be able to use a dynamic key value to be able to transform it and obtain a different number as the value to it's key. Is there a way to accomplish this using ES6?
*EDIT 1: * The function is not the issue here, I had a few errors but would have definitely been able to fix it by myself, I want to be able to retrieve a value from an object based on the key itself.
map? There is noreturninside of it. And whrere is your array to usemap?mapa method of strings?forEach().forEachmethod either.forEacheither