I am having an issue where .find() is not working on my Chrome browser when I use it in AngularJS. This was my original question: AngularJS: Array.prototype.find() does not work in Chrome
It's failing on this line:
console.log($scope.products_colors); // prints `[Object]0: Objectlength: 1__proto__: Array[0]concat: function concat() { [native code] }constructor: function Array() { [native code] }every: function every() { [native code] }filter: function filter() { [native code] }forEach: function forEach() { [native code] }indexOf: function indexOf() { [native code] }join: function join() { [native code] }lastIndexOf: function lastIndexOf() { [native code] }length: 0map: function map() { [native code] }pop: function pop() { [native code] }push: function push() { [native code] }reduce: function reduce() { [native code] }reduceRight: function reduceRight() { [native code] }reverse: function reverse() { [native code] }shift: function shift() { [native code] }slice: function slice() { [native code] }some: function some() { [native code] }sort: function sort() { [native code] }splice: function splice() { [native code] }toLocaleString: function toLocaleString() { [native code] }toString: function toString() { [native code] }unshift: function unshift() { [native code] }__proto__: Object mens_detail_controller.js?body=1:24`
$scope.selected_color = $scope.products_colors.find(function(el) {
return el.id == 91;
});
I know it's failing on .find, because the code works when I replace it with something else.
Is there an alternative to looking through an array and grabbing the first element with a certain condition in javascript?
xs.filter(f)[0].filter()better than patching it? It's potentially less efficient since it has to search the entire Array, whereas.find()stops as soon as it finds a match.