我需要将??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])使用“索引器”表示法。有没有办法绕过它?(我事先不知道过滤器属性的名称,也不想对其进行迭代)。