If I have a bunch of objects, and within these objects is the string "id" (which is the same as the object name) how can I use this string to reference the object?
Example:
//These objects are tests - note the id's are the same as the object name
var test1 = {
id : "test1",
data : "Test 1 test 1 test 1"
}
var test2 = {
id : "test2",
data : "Test 2 test 2 test 2"
}
/* ----- My Function ----- */
var myObj = null;
function setMyObj(obj){
myObj = obj;
}
setMyObj(test1);
/* ----- My Function ----- */
Now, if I call the following:
myObj.id;
The Result is "test1" (a string). If I want to use this to get the data from test1, how would I do so?
"myObj.id".data
[myObj.id].data
^^^
These don't work!
Cheers, Rich
myObj.data
should do the job. – Furqan Jun 19 at 14:04