Creating fresh texts by pairing the values in constants with variables

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.

Preview of webpage

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)

Answer №1

It is uncertain whether the l18 refers to a number or a word. However, I have outlined various methods you can use to convert one to the other.

The only issue is that JavaScript has a limitation on integer size, so numbers like 55254206302462116 are too large and should be stored as strings instead.

const StockCodes = {
  آبادا: ["37661500521100963"],
  آپ: ["55254206302462116"],
  آسيا: ["51106317433079213"],
};

var l18 = "آبادا"
var code = StockCodes[l18][0]
console.log(code)

// conversion in the opposite direction
var l18 = "55254206302462116"
var StockCodesInv = Object.entries(StockCodes).reduce(function(agg, [key, value]) {
  agg["" + value[0]] = key;
  return agg;
}, {});
var company = StockCodesInv[l18]
console.log(company)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Designing a menu header against a specific background color resulting in misalignment

I have been working on creating a menu header for my website. If you would like to take a look, here is the link to my jsfiddle page. Unfortunately, I am facing an issue where all my images and text should remain in that grey color scheme but somehow it& ...

AngularJS textbox validation for numbers and required in repeating mode ensures that the user input is a

For more information, please visit the following link: https://plnkr.co/edit/9HbLMBUw0Q6mj7oyCahP?p=preview var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope) { $scope.NDCarray = [{val: '' ...

Utilizing Jquery or Javascript to Establish a Fresh Perspective for CylinderGeometry with Three.js

I'm attempting to change the dimensions of a cylinder created using examples from Three.js at runtime, but my code doesn't seem to be working. Here is the code snippet I am using: HTML <script src="http://www.html5canvastutorials.com/librari ...

Styled-components does not generate a style tag as output

After creating a new project in React with Webpack, I decided to experiment with Styled Components. In my index.js file, the code is structured like this: import React from "react" import ReactDOM from "react-dom" import Page from "./site/Page" import s ...

eliminate empty lines from csv files during the uploading process in Angular

I have implemented a csv-reader directive that allows users to upload a CSV file. However, I have noticed an issue when uploading a file with spaces between words, resulting in blank lines being displayed. Here is an example: var reader = new FileReader ...

The Bar Graph Transition in d3 is Running Backwards

Learning to code has been a fascinating journey for me, but I must admit that JavaScript presents a unique challenge. Currently, I am working on creating a d3.js Bar Chart and I wanted to include a transition effect when the bars load. However, I have enco ...

execute javascript code after loading ajax content

Although this question may have been asked before, I am completely unfamiliar with the subject and unable to apply the existing answers. Despite following tutorials for every script on my page, I have encountered a problem. Specifically, I have a section w ...

Python 3 encountered a division by zero error in the reporthook function

Currently, I am in the process of creating a basic code that can download 4365 files (.mp4, .wmv, .jpeg & .pdf) from a .json file. The downloading aspect is working fine, but I am interested in implementing a reporthook feature to display information s ...

Navigate through the rows and columns of an HTML table by utilizing Javascript with webdriver, specifically for Protractor in a non-angular environment

I need help with iterating through rows and columns using Selenium Webdriver. I am currently using Protractor for a non-angular web page. I have some Java code that works with the WebElement class to get the number of links, but now I need to transition th ...

Traverse through an array of objects with unspecified length and undefined key names

Consider the following object arrays: 1. [{id:'1', code:'somecode', desc:'this is the description'}, {...}, {...}] 2. [{fname:'name', lname:'last name', address:'my address', email:'<a h ...

Determine whether a WebElement contains a particular content within the :after pseudo class

After locating my element in Selenium, I've come across an interesting challenge. IWebElement icon = box.FindElement(By.ClassName("box-icon")); Sometimes, this element (icon) has a content set as follows: &:after { content: $icon-specia ...

What causes queryAsync() to generate additional metadata?

Following the instructions provided in a response to a question, I utilized queryAsync() and it is functional. However, it is appending excessive meta data to my query result, which was initially a simple query. This is the code snippet I am using to exec ...

utilizing an arrow function in the same manner as a traditional function

I am a fan of the new arrow ()=>{} syntax and would love to use it wherever possible. I understand that arrow functions point to the outer this context. Is there a way to modify an arrow function so that "this" points to its inner scope? For example, h ...

Arranging data structures in JavaScript: Associative arrays

I'm facing a major issue. My task is to organize an array structured like this: '0' ... '0' ... 'id' => "XXXXX" 'from' ... 'name' => "XXXX" ...

Material-inspired Design Device Compatible DIV slide with JS, JQuery, and CSS

My goal is to achieve something similar to this: Desired Live Website I am looking for a feature where clicking on the div will slide in content from the right, load an external page inside it, and close when prompted. The slider div should be device c ...

Tips for optimizing the page speed of your Pixi JS app by ensuring it runs efficiently after the page loads

On my website, I implemented a dynamic gradient animation with shape-changing blobs using pixi js. The animation functions flawlessly, but the issue arises when I run page speed tests - the test assumes that the page has not finished rendering because the ...

Update the ng-model in AngularJS when the value is set to true

Hello there, I am in the process of developing an app that provides a summary of data from a database. In this app, there is a form that populates input fields with information using ng-model. Users can edit these values as needed. However, I want to ensu ...

Handling JSON Deserialization Error in C# with jQuery and ASMX

Trying to perform an AJAX POST request to a C# ASMX web method, but encountering issues with JSON data deserialization. Despite following the correct steps, I keep getting the error message... {"Message":"Cannot convert object of type \u0027System.St ...

Understanding special characters within a URL

Here is a URL example: postgres://someuser:pas#%w#@rd-some-db.cgosdsd8op.us-east-1.rds.amazonaws.com:5432 This URL is being parsed using the following code snippet: const url = require('url'); const { hostname: host, port, auth, path } = url.par ...

Trouble arises when attempting to utilize the WCF restful service through an Ajax call

I've created a WCF restful service that has a login method exposed to the outside world. The purpose of this method is to validate user credentials with a database (specifically the login table) and return the result in json format. C# code: [Operat ...