Home>

Purpose

I want to use a variable that is a combination of a variable and a character string as a variable
Sorry for the poor explanation.

For example, when executing such a script, an error will be thrown only for the best processing.

var Over= "Overrrrr"
var Page= "Stack" + Over + "Flow"
JSON.parse (httpObj.response) .Ids.find ((v)= >
 v.User== "Overrrrr");
JSON.parse (httpObj.response) .Ids.find ((v)= >
 v.User== Over);
JSON.parse (httpObj.response) .Ids.find ((v)= >
 v.User== Over) .StackOverrrrrFlow;
JSON.parse (httpObj.response) .Ids.find ((v)= >
 v.User== Over) .Page;

.StackOverrrrrFlowWas combined with a character string.PageI think it's because I'm trying to do it in, but how can I improve it to make it work?

Addendum

Added the content that is actually displayed. Sorry for the inconvenience.

JSON.parse (httpObj.response) .Ids.find ((v)= >
 v.User== "Overrrrr");
//Object {User: Overrrrr, Id: "82955", StackOverrrrrFlow: "DOTCOM"}
JSON.parse (httpObj.response) .Ids.find ((v)= >
 v.User== Over);
//Object {User: Overrrrr, Id: "82955", StackOverrrrrFlow: "DOTCOM"}
JSON.parse (httpObj.response) .Ids.find ((v)= >
 v.User== Over) .StackOverrrrrFlow;
//"DOTCOM"
JSON.parse (httpObj.response) .Ids.find ((v)= >
 v.User== Over) .Page;
//undefined

"DOTCOM"I want to get

What exactly is in JSON.parse (httpObj.response) .Ids, what kind of result do you want find ((v)=>v.User== Over) .Page to have, and what kind of error do you actually get? Do you vomit? The code in the second half has to be eval (t2), but I have a feeling that it has nothing to do with the problem in the first half.

int32_t2021-10-14 03:59:35

Thank you for your reply. I added it. Also, the latter half seems to be irrelevant, so I deleted it. I am terribly sorry. In addition, we solved it by the method that another person answered.

水瀬敦美2021-10-14 03:59:35
  • Answer # 1
    I'd like you to write a little concrete input and output for

    , but if you answer with a guess,

    JSON.parse (httpObj.response) .Ids.find ((v)= >
     v.User== Over) [Page];
    
    Isn't it

    ?

    To access a string as a variable nameeval ()Is required, but to use a string as a property name[]You can access it with.

    Thank you for your reply. We apologize for the inconvenience caused by our lack of explanation. As a result of trying with the method you taught, I got the desired result safely.

    水瀬敦美2021-10-14 03:59:35
  • Answer # 2
    I'd like you to write a little concrete input and output for

    , but if you answer with a guess,

    JSON.parse (httpObj.response) .Ids.find ((v)= >
     v.User== Over) [Page];
    
    Isn't it

    ?

    To access a string as a variable nameeval ()Is required, but to use a string as a property name[]You can access it with.

    Thank you for your reply. We apologize for the inconvenience caused by our lack of explanation. As a result of trying with the method you taught, I got the desired result safely.

    水瀬敦美2021-10-14 03:59:35