我必须执行LOT查找,同时解析xmlStream如果我需要一些标签或没有.
我可以使用array.indexOf方法(我在数组中有约15项)或使用object [key]查找.
对我来说,第二种解决方案在理论上似乎更有效,但在我的代码中看起来并不好看.但如果真的更有效率,我会保持原样.
例如:
var tags = [
'tag1',
'tag2',
'tag3',
...
];
var tags2 = {
'tag1' : null,
'tag2' : null,
'tag3' : null,
}
tags.indexOf(value) // exists?
tags2[value] // exists?
Run Code Online (Sandbox Code Playgroud)