Make sure to carefully read the question before proceeding.
I have attempted multiple commands in order to retrieve a single variable from the server [TSE](https://old.tsetmc.com/Loader.aspx?ParTree=15131F) which serves Stock Exchange information. The page is essentially a JavaScript playground utilizing Filters that can be viewed by pressing F12, entering the console, and pasting the command:
JSON.parse( localStorage.MarketWatchSettings)['Filters']
You can also write codes in the text field provided on the page once you enter.
The variable I am interested in is *(l18)*, representing the company name. This particular server does not grant user access and only provides specific information upon request.
The main question at hand: how can we assign a number to each company name listed in order to generate a link from the server opening with [text](http://www.tsetmc.com/InstInfo) followed by a set of numbers like [text](http://www.tsetmc.com/InstInfo/25244329144808274) for the largest company named "Fars"?
Here is a condensed preview of the long list prepared:
const StockCodes = {
آبادا: [37661500521100963],
آپ: [55254206302462116],
آسيا: [51106317433079213],
};
We need to match the live retrieved string (l18) with the keys in the constant above and use the corresponding value (number). This number will then complete the link resulting in a new link such as .
I have tried three different solutions, detailed below:
1. *Constant itself*:
var Names = StockCodes.(l18)
var url = String.fromCodePoint(StockCodes);
var finalLink = "http://www.tsetmc.com/InstInfo/"+url
console.log(finalLink)
2. *Includes*:
var Names = StockCodes.(l18)
if (StockCodes.includes((l18)))
{var finalLink ="http://www.tsetmc.com/InstInfo/"+Names}
console.log(finalLink)
3. *Match*:
let resultofsearch = StockCodes.match((l18));
var TSEPage = TSEPageCode(StockCodes.resultofsearch)
var finalLink = "http://www.tsetmc.com/InstInfo/"+TSEPage
console.log(finalLink)
The (l18) represents a company name consisting of letters or alphanumeric characters along with whitespace at times.
An issue arises when dealing with strings containing parentheses, making it impossible to call rows using them. Additionally, what about strings starting and ending with parentheses like `"(tmin)"` for lowest price?
We cannot incorporate: "...StockCodes.(l18)"
within the code since it results in an error:
TypeError:StockCodes.row is undefined
All codes consolidated in one place:
var companyname = (l18) && (l18) = "آبادا"
const StockCodes = {
آبادا: [37661500521100963],
آپ: [55254206302462116],
آسيا: [51106317433079213],
};
var Names = StockCodes.(l18)
var url = String.fromCodePoint(StockCodes);
var finalLink = "http://www.tsetmc.com/InstInfo/"+url
console.log(finalLink)
var Names = StockCodes.(l18)
if (StockCodes.includes((l18)))
{var finalLink ="http://www.tsetmc.com/InstInfo/"+Names}
console.log(finalLink)
let resultofsearch = StockCodes.match((l18));
var TSEPage = TSEPageCode(StockCodes.resultofsearch)
var finalLink = "http://www.tsetmc.com/InstInfo/"+TSEPage
console.log(finalLink)