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,如:
Id 为 ss,item值为”dd”。
那么,如何来遍历一个jq类的所有属性呢?,可以如下:
$.each(obj, function(key, element) { alert('key: ' + key + '\n' + 'value: ' + element); });
或者:
for(var key in obj) { alert('key: ' + key + '\n' + 'value: ' + obj[key]); }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步