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

What is the best way to ensure that the HTML page is only shown once all data from three JSON files has been fully

I have successfully parsed data from three different JSON files using the code below. //factory app.factory('myapp', ['$http', function($http) { function getLists() { var tab = [&a ...

Encountering an issue with the history module when utilizing the webpack dev server

I am encountering an issue while trying to run webpack dev server. The history functionality was working fine until I started using the webpack module. A warning message appeared in my console: WARNING in ./src/history.js 2:15-35 export 'createBrows ...

Why is it that when I refresh a page on localhost, the file download gets stuck until I close the page?

As I work on my HTML/JS files hosted on localhost with Node, I've noticed that when I make changes to the code, Webpack automatically rebuilds the JS files. However, there are times when, after making updates and trying to refresh the page, the downl ...

Draggable HighStock element causing issues with Gridster dragging

I have integrated a stocks chart from HighStocks with gridster, where each gridster block is draggable. However, the stocks time slider gadget can also be dragged and resized. When I move the slider on top of a gridster widget, the entire widget moves alon ...

The Ejs page is failing to render on the simplified code version

Here is the code that displays the 'post' page: app.get("/posts/:postName", function(req, res) { const requestedTitle = _.lowerCase(req.params.postName); posts.forEach(function(post) { const storedTitle = _.lowerCase(post.title ...

Ways to access the entire parent element, rather than just the individual child element, following the use of e.target

Looking to target the li element itself when clicked, rather than its child elements. The goal is to determine which specific option the user selects from a dropdown menu using event.target in jQuery. If the user chooses an li with a class of 1, set one gl ...

Risks associated with storing configuration files in JSON/CPickle are related to security

In search of a secure and flexible solution for storing credentials in a config file for database connections and other private information within a Python module. This module is responsible for logging user activity in the system through different handler ...

Exploring the integration of Stripe Checkout with React and Express.js

Seeking assistance with integrating Stripe Checkout into my React application. I need to create a route in my nodejs/express server that will provide the session id required for setting up Stripe Checkout on the front end. The aim is to redirect users to s ...

Building with bricks and mortar does not involve organizing visual content

I'm currently trying to organize some fairly large images using masonry, but the code below doesn't seem to be working. I'm using node.js with express and have installed the masonryjs package in an attempt to make it work, but that approach ...

Display confirmation pop-up when clicking outside of the modal window in Bootstrap

I am currently utilizing AngularJS (1.5.9) and ui-bootstrap in my application. I am looking to display a confirmation popup if the user clicks outside of an already open modal. I have attempted using both controlled exit with $uibModalInstance.close() and ...

Retrieving information from a list in R

library(httr) library(jsonlite) response <- GET('https://extraction.import.io/query/runtime/17d882b5-c118-4f27-8ce1-90085ec0b116?_apikey=d5a8a01e20174e95887dc0f385e4e3f6d7ef5ca1428d5a029f2aa352509948ade8e5d7fb0dc941f4769a32b541ca6b38a7cd6578dfd81b3 ...

Forcing a property binding update in Angular 2

Take a look at this particular component import {Component} from 'angular2/core' @Component({ selector: 'my-app', providers: [], template: ` <div> <h3>Input with two decimals</h3> <input type ...

Incorporating Framer Motion into traditional React class components (non-functional approach)

I'm encountering an issue with a simple animation using Framer Motion that functions correctly in a functional component, but fails to work in a class component. I am new to Framer Motion and here is my react code => import {motion} from 'fr ...

Executing a post request using axios

Having some trouble with a post request using axios and it's refusing to cooperate. Here is the specific request I need to make. This is what I attempted: await axios.post( 'https://api.searchads.apple.com/api/v4/campaigns/XXXX/adgroups/targ ...

JavaScript has the ability to manipulate the width of an element by using methods to both retrieve

I have a unique situation where I need to dynamically adjust the width of a ul list element based on the text content inside it. Specifically, I want the width of the ul list to be equal to the width of the first list item, which can change frequently. My ...

Having trouble retrieving the data property from the parent component within the child component slot

I am facing an issue with my Vue components. I have a rad-list component and a rad-card component. In the rad-list component, I have placed a slot element where I intend to place instances of rad-card. The rad-card component needs to receive objects from t ...

What is the best way to distribute my rabbitMQ code among different components?

I am looking for a way to optimize my rabbitMQ connection code by creating it once and using it across multiple components. Currently, every time I need to pass data to my exchange and queue, I end up opening and closing the connection and channel multiple ...

Ensure that the textbox remains valid when the reset button is clicked in Bootstrap

After implementing the code for bootstrap textbox and textarea, I encountered an issue when using the reset button. When entering an invalid shop name followed by a valid address and clicking on the Reset button, it resets the form. However, if I then only ...

Exploring the integration of React Context API within a Next.js application to streamline the authentication process

I am looking to build a react app using Next.js. However, I am currently stuck and need assistance in figuring out how to proceed. I have implemented user authentication on the backend with node.js, passport.js, passport-local-mongoose, and express.sessi ...

What is the best way to find the index of the smallest value in an array using JavaScript?

I recently created this function that currently outputs -1. function sayHello() { let buildingLevelsArray = [11,10,10]; var smallestIndex = buildingLevelsArray.indexOf(Math.max(buildingLevelsArray)); console.log(smallestIndex); } sayHello() ...