javascript - Have a variable select from an array -


this question has answer here:

i trying use variable select array:

this works:

var myarray = {bricks:3000, studs:500, shingles:400, tiles:700};  function one() {    alert(myarray.bricks); } 

but not work:

var myarray = {bricks:3000, studs:500, shingles:400, tiles:700};  var myvalue = "bricks"  function two() {    alert(myarray.myvalue); } 

how do properly? here fiddle show trying accomplish: https://jsfiddle.net/chrislascelles/xhmx7hgc/2/

use [] notation.

var myarray = {bricks:3000, studs:500, shingles:400, tiles:700};  function one() {        alert(myarray.bricks); }   var myvalue = "bricks"  //supplied here make example work  function two() {        alert(myarray[myvalue]); } 

demo


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -