我需要将??
C# 运算符应用于 JavaScript,但我不知道如何操作。在 C# 中考虑这一点:
int i?=null;
int j=i ?? 10;//j is now 10
现在我在 JavaScript 中设置了这个:
var options={
filters:{
firstName:'abc'
}
};
var filter=options.filters[0]||'';//should get 'abc' here, it doesn't happen
var filter2=options.filters[1]||'';//should get empty string here, because there is only one filter
我该怎么做才能正确?
谢谢。
编辑:我发现了一半的问题:我不能对对象 ( my_object[0]
)使用“索引器”符号。有没有办法绕过它?(我事先不知道过滤器属性的名称,也不想遍历它们)。