1

I have the following viable as an example: "ratioSize": "LP555/12317 Z ABCD"

in my each function inside my getJson call:

 $.each(data.infoData, function (i, item) {
                // console.log(Rating); works just fine
                //console.log(stockNumber ); works just fine

            var Rating = this.tireRating;
            var stockNumber = this.SN;
            var ratioSize = this.TS
            var NEW_VARIALBE_I_NEED = the last 2 number of the FIRST PART of ratioSize, so in this case it is 17


        });

any ideas of how I can make that into one of my variables? I'm totally lost here

5
  • What format are those strings going to be? We can potentially take a substring, or we can go for a regular expression match! Commented May 19, 2015 at 1:39
  • I am going to produce list items from there. The list items ID would be that new variable Commented May 19, 2015 at 1:42
  • Sorry, what format are the ratioSize strings going to be? Always 2 letters, 3 digits, slash, five digits, space, one letter, space, four letters? Commented May 19, 2015 at 1:43
  • My bad, trying figure out and understand it as I go. It will always be the last 2 number of the first part of the string. But yes, it should always be in that format I showed you, the 2 parts the one letter, and four letters. Those could be numbers. But the first part will always be in the same format Commented May 19, 2015 at 1:51
  • Okay, cool. Well, as long as the position and length of that "17" substring remains constant, then we can simply grab a substring! Commented May 19, 2015 at 1:53

2 Answers 2

1

Assuming the position and length of the "17" string doesn't change, we can simply grab a substring:

var ratioSize = "LP555/12317 Z ABCD";
var result = ratioSize.substring(9, 11);
Sign up to request clarification or add additional context in comments.

Comments

1

I'm not exactly sure of what you're asking, in order to get the characters you want, do this:

var Rating = this.tireRating;
var stockNumber = this.SN;
var ratioSize = this.TS
var ratioSplit=ratioSize.split(' ');
var variable=ratioSize.slice(ratioSplit[0].length-2,ratioSplit[0].length);

variable is now 17 from your example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.