Javascript数组操作及索引

1:清空数组最高效的做法

parentThis.PaperQuestionStrategiesList.length = 0;

 

2:push and pop

parentThis.PaperQuestionStrategiesList.push(questionStrategy);

 

3:字符串索引

parentThis.QuestionUnits[i] = parentThis.QuestionUnits[item.Id] = item;

从本质上来说,QuestionUnits[item.Id],实际上是为QuestionUnits对象创建了一个属性,该属性名为item.Id,如:

image

Id 为 ss,item值为”dd”。

那么,如何来遍历一个jq类的所有属性呢?,可以如下:

$.each(obj, function(key, element) { alert('key: ' + key + ' ' + 'value: ' + element); });

或者:

for(var key in obj) { alert('key: ' + key + ' ' + 'value: ' + obj[key]); }

原文地址:https://www.cnblogs.com/luminji/p/3408438.html