简体   繁体   中英

Get data from array of object and put it to key value

I want to take that._mCon.usa which have array of object's and put the data like key value in _mUsa object,In the object instance I've name and path ,I try like following and its not working the _mUsa is not filled with data...any idea what im doing wrong here ?

_mUsa{

},

for(var i = 0; i <= that._mCon.usa.length; i++) {

that._mUsa[that._mCon.usa[i][name]] = that._mUsa[that._mCon.usa[i][path]];

}

this is that._mCon.usa with the name and path properties

在此处输入图片说明

Object properties are accessed using .propertyname , so it should be:

that._mUsa[that._mCon.usa[i].name] = that._mUsa[that._mCon.usa[i].path];

You use [name] when the property name is dynamic, and name is a variable containing the property name.

You can use [] with a literal string, eg ['name'] and ['path'] , but there's little point to that; if the property is known, just use the normal dot notation.

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