Javascript Array contains(obj)
Array.prototype.contains = function(obj) { for(i=0;i<this.length;i+=1) {// w w w .j a v a 2s .co m if(this[i] === obj) { return true; } } return false; }
Array.prototype.contains = function(obj) { var i = this.length; while (i--) {// w ww. j ava 2 s. c o m if (this[i] === obj) { return true; } } return false; }
Array.prototype.contains = function (obj) { return this.indexOf(obj) > -1; };
Array.prototype.contains = function (obj) { return this.indexOf(obj) >= 0; };
/*jshint esnext: true */ Array.prototype.contains = function(obj) { var i = this.length; while (i--) { if (this[i] === obj) { return true; }//from ww w .j a va 2 s. co m } return false; };
'use strict';// ww w. j a v a 2 s .co m Array.prototype.contains= function (obj) { for(let i = 0; i < this.length; i++) { if(this[i].key === obj) { return true; } } return false; } function countSameElements(collection) { let result = []; collection.filter(function (item) { let itemArray = collection.filter(function (value) { if(value === item) { return true; } }); let obj = {}; obj.key = item; obj.count = itemArray.length; if(result.contains(obj.key) === false) { result.push(obj); } }); return result; }
//Helper function, to check if a Array contains a other object Array.prototype.contains = function contains(obj) { for (var i = 0; i < this.length; i++) { if (this[i] === obj) { return true; }//from w w w. j av a2 s. c o m } return false; };