Accessing Object Properties with Variables
var dogs = {
Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle"
};
var myDog = "Hunter";
var myBreed = dogs[myDog];
console.log(myBreed); // "Doberman"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"
Also in JavaScript:
- how to check if value is undefines if condition jquery
- js array as parameter
- how get checkbox if checked in jquery
- routes in node js
- how to find remainder in javascript
- javascript clone object
- MERN Stack React Node Ecommerce from Scratch to Deployment
- Exception in thread "main" org.openqa.selenium.JavascriptException:
- how to send enter event to input field jquery
- javascript generate unique id
- how to access global scope in to local scope using javascript examples
- jquery window new tab with post
- readfilesync
- javascript add object to array
- jquery ui dialog position fixed center
- how to flip a Number in javascript
- random numbers javascript
- javascript 1 + "1"
- make forn awesome icon clickable in react
- dart code formatter vscode
- javascript get point of line intersection
- javascript confirm yes no
- calculate log in javascript
- how to make a sprite javascript