Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Accessing Object Properties with Variables

var someObj = {
  propName: "John"
};
function propPrefix(str) {
  var s = "prop";
  return s + str;
}
var someProp = propPrefix("Name"); // someProp now holds the value 'propName'
console.log(someObj[someProp]); // "John"
 
PREVIOUS NEXT
Tagged: #Accessing #Object #Properties #Variables
ADD COMMENT
Topic
Name
1+5 =