hi :如下是 linq to js 的分享 ,如有雷同 纯属巧合
(function () { Array.prototype.first = function (predicate, def) { var l = this.length; if (!predicate) return l ? this[0] : def == null ? null : def; for (var i = 0; i < l; i++) if (predicate(this[i], i, this)) return this[i]; return def == null ? null : def; }; Array.prototype.where = Array.prototype.filter || function (predicate, context) { context = context || window; var arr = []; var l = this.length; for (var i = 0; i < l; i++) if (predicate.call(context, this[i], i, this) === true) arr.push(this[i]); return arr; }; Array.prototype.select = Array.prototype.map || function (selector, context) { context = context || window; var arr = []; var l = this.length; for (var i = 0; i < l; i++) arr.push(selector.call(context, this[i], i, this)); return arr; }; })(); 使用方法:list.first(function (t) { return t.Value.trim() == city.trim(); });
原文地址:https://www.cnblogs.com/xiebingshare/p/8674979.html
时间: 2024-09-29 08:51:28