0
let script_type = {'vpl_run.sh':0,'vpl_debug.sh':1,'vpl_evaluate.sh':2,'vpl_evaluate.cases':2};
let list = ['vpl_run.sh','vpl_debug.sh', 'vpl_evaluate.sh', 'vpl_evaluate.cases'];
for (let i = 0, len = list.length; i < len; i++) {
    let fileName = list[i];
    console.log(script_type.fileName);
}

Always getting undefined in console log

Note : variable fileName has value as "vpl_run.sh" with dot (.) what exactly I need is

    0
    1
    2
    2
2
  • 2
    Just do script_type[fileName] Commented Jan 28, 2018 at 7:47
  • You are accessing your dictionary data as if it was a list. Commented Jan 28, 2018 at 7:49

2 Answers 2

3

Instead of console.log(script_type.fileName);, do:

console.log(script_type[fileName]);.

Sign up to request clarification or add additional context in comments.

Comments

1

This is trivial in JS.

Just do script_type[fileName] and you have it.

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.