[How] can I achieve the following?
var object = new Object(); object.field1 = "test1"; object.fiedl2 = "test2"; function showSpecificField(fieldName){ //get the field Name passed in to function from object //something like: return object.fieldName ??? } alert(showSpecificField("field2"));// should alert the text "test2" alert(showSpecificField("field1"));// should alert the text "test1"
Use square bracket designation
var baz = 'bar'; foo['bar'] === foo.bar === foo[baz]
Source: https://habr.com/ru/post/888636/More articles:Measuring distance along an ellipse - c ++Do not see the Entity Framework template after installing Visual Studio 2010 on Windows 7 64-bit - windows-7How to add Title to Spinner in android - androidGetting the "missing primary name on the way" when trying to access the Solr administrator installed on Glassfish - glassfishHow to filter all variants of the general type using OfType <> - genericsRegister and use the registrar with Unity in global.asax - asp.netWindows Search sql - cannot access System.Search.QueryFocusedSummary - c #GROUP BY Query Optimization - mysqlWhat is the HTML5 Semantic Layout? - html5Download RequestTimeout on S3 using PHP - phpAll Articles