简体   繁体   中英

How to assign a value of variable as name of an object in javascript

I pass a string through "objName".

I want this to to be stored in the line: facebookData.objName

For example:

if I invoke the function like, fetchData(0, response, "friendsCount") , the object should be like: facebookData.friendsCount = dLen;

Note: facebookData is a global object.

             function fetchData(dLen, response, objName){

                if(response.paging){

                    if(!response.paging.next){

                        facebookData.objName = dLen; //Problem is here
                        return dLen;
                    }
                    else{
                        -------------------
                       fetchData(dLen, response, objName);
                    }
                }

使用括号:

facebookData[objName] = dLen;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM