ive got an object:
var car = {
company: "Honda",
year: "2011",
Model: "Brio"
}
I was wondering if there exists an inherited method (is that the right phrase?) to check if a value exists inside a given object, somewhat like x.hasOwnProperty
, or if (x in car)
. Or, should I write my own.
I've done a few google searches, but they all either lead to hasOwnProperty
or to check if a value exists inside an array.
Editing to please all the people in the comments: There are two use cases i could think of where this would be useful:
checking for undefined keys and reporting which one
if (!car.isInvalid(car, undefined)) validCarsArray.push (car);
Checking if a general user input exists in an object
var text = searchBox.input; validCarArrays.forEach (function (car) { if (car.hasOwnValue(car, text)) { displayToUserAsResult (car); } });