How do I a get SPECIFIC string from webpage and then use it in my own JavaScript code?

So basically, I need to get a SPECIFIC number from a website’s page source via Google Chrome and then use that number in my own js code. The number from the website is not from it’s HTML, but from one of it’s scripts. There are some pictures below to help you better understand.

View image here, because I don’t have enough ‘reputation points’…

As you can see in the picutre circled in red, that is the number I want to take. It changes everytime the page reloads so I need a script (if possible) that will reload the page, find and take that number (it will change everytime it reloads), and then use it in my own JavaScript function as a variable or something.

The url in Google Chrome is: “view-source:http://www.investopedia.com/simulator/portfolio/?gameid=383710

NOTE: Because this is from a page where the user has to be signed in, you will not get the same page source code but that’s why I gave you a picture.

I have searched everywhere on the internet and cannot find any answer to my question so maybe you could help. Thanks a lot!


Source: stackoverflow-javascript

How do I call for a certain variable or another depending on a string I have

I have two variables, varL and varR, which have the information that they are L and R respectively. Depending on wether a third object has as imput ‘L’ or ‘R’, I would like to reference varL or varR respectively. Is there any way to do this?

Specifically, varL and varR are arrays. If the third object has as imput ‘L’, I would like to have access to varL[i] for some i, and the same goes for ‘R’. I know this is not even remotely correct, but I was looking for something like

(var +’L’)[i] or something


Source: stackoverflow-javascript

String to Object with JavaScript

I would like to know the most efficient way to convert this string into an object in JavaScript.

This is the ugly string:

  ""date","initRegistrations","registrations","finalizeRegistrations"rn"03/29/2017","0","0","0"rn"03/30/2017","5","4","4"rn"03/31/2017","42","0","0"rn"04/01/2017","192","0","0"rn"04/02/2017","4","0","0"rn"04/03/2017","23","0","0"rn"04/04/2017","5","0","0"rn"

At the moment I’m using this function, but it does not work fine, the expected output would be a object of object with the keys date, initRegistrations, registrations, finalizeRegistrations:

   function convertToArrayOfObjects(data) {
    var keys = data.shift(),
        i = 0, k = 0,
        obj = null,
        output = [];

    for (i = 0; i < data.length; i++) {
        obj = {};

        for (k = 0; k < keys.length; k++) {
          if(data[i][k]){
            obj[keys[k]] = data[i][k];
          }

        }

        output.push(obj);
    }

    return output;
}

Is there any fancy way to achieve this easily or I should go playing with my array of objects?
Any help or advice is appreciated.
Thanks.


Source: stackoverflow-javascript

Splitting a Long String Into Multiple Lines using javascript

I have the following string:

"The water content is considered acceptable for this voltage class. Dielectric Breakdown Voltage is unacceptable for transformers > 288 KV. Power factors, Interfacial Tension and Neutralization Number are acceptable for continued use in-service.".

I want to split the string into lines so that every line will contain at max 5 sentences in each line.

I want to control the number of sentences in each line dynamically, so that tomorrow I will be able to split the string into lines where each line contain at max N sentences in each line.


Source: stackoverflow-javascript