0

Now I am sending length as a string as a function parameter.

function sample(operation){
var str="hello";
console.log(str.operation);
}

sample("length");

I am not allowed to change the way I am sending length(has to be a string).What can I do for this function to give me the expected output?

Sathwic
  • 53
  • 5

1 Answers1

1

If you just want to access the property, use bracket notation for your property accessor:

console.log(str[operation])
Donut
  • 110,061
  • 20
  • 134
  • 146