Question: In this code fragment

```
foreach (var row in grid.Rows) { }              

```

the type of row is inferred as Object instead of GridViewRow. I have to explicitly declare the type to work with a GridViewRow:

```
foreach (GridViewRow row in grid.Rows) { }

```

GridView.Rows returns a GridViewRowCollection and GetEnumerator on the collection "Returns an enumerator that contains all GridViewRow objects in the GridViewRowCollection." If I access a single row from the collection by index

```
var row = grid.Rows[0];

```

the type is correctly inferred. Why can't the compiler infer the type for row in the foreach declaration?

Edited to add: Interesting responses, I didn't think to look for the obvious problem. ListView.Items implements `IList<ListViewDataItem>`, so this looks like an oversight to me.

Answer: 
If you are using [underscore.js](http://underscorejs.org/) library then object/array operations become simple. 

In your case \_.has method can be used. Example:

```
yourArray = {age: "10"}

_.has(yourArray, "age")

```

returns **true** 

But,

```
_.has(yourArray, "invalidKey")

```

returns **false**
An alternate approach using "Reflect"
=====================================

As per [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect)

> 
> Reflect is a built-in object that provides methods for interceptable
> JavaScript operations.
> 
> 
> The static Reflect.has() method works like the in operator as a
> function.
> 
> 
> 

```js
var obj = {
  a: undefined,
  b: 1,
  c: "hello world"
}
console.log(Reflect.has(obj, 'a'))
console.log(Reflect.has(obj, 'b'))
console.log(Reflect.has(obj, 'c'))
console.log(Reflect.has(obj, 'd'))
```

Should I use it ?
-----------------

It depends.

`Reflect.has()` is slower than the other methods mentioned on the accepted answer (as per my benchmark test). But, if you are using it only a few times in your code, I don't see much issues with this approach.