You will need to create your own search function.
Array.prototype.findMovieByYear = function (findYear) { for (var i = 0; i < this.length; i++) { // this actually returns the element, maybe you just want // to return the array index ( the i param ) if (this[i].Release == findYear) return this[i]; } return null; // or return -1 or whatever if you want to return the index }; // now you can call: movies.findMovieByYear('1998'); // and that should return { Name: "The Red Violin", ReleaseYear: "1998", Director: "François Girard" }
Of course, this way of doing this actually affects every array you create. Perhaps this is not what you want .. you can create your own array object, then ...
source share