JavaScript
4
Вклад в тег
Array.isArray = function(obj) {
return /^\[object (NodeList|Array)\]$/.test(Object.prototype.toString.call(obj));
};
Document.prototype.addClass =
DocumentFragment.prototype.addClass =
NodeList.prototype.addClass =
Element.prototype.addClass = function(value) {
if( typeof value === "string" && value ) {
var j, current, clazz, finalValue;
var stripAndCollapse = function(v, a) {
var tokens = v.match(/[^\x20\t\r\n\f]+/g) || [];
return a ? tokens : tokens.join(" ");
}, classList = stripAndCollapse(value, true);
var list; Array.isArray(this) ? (list = this) : (list = [], list.push(this));
list.forEach(function(elem, i) {
// This expression is here for better compressibility (see addClass)
current = elem.nodeType === 1 && (" " + stripAndCollapse(elem.className) + " ");
if( current ) {
j = 0;
while( (clazz = classList[j++]) ) {
if( current.indexOf(" " + clazz + " ") < 0 ) {
current += clazz + " ";
}
}
// Only assign if different to avoid unneeded rendering.
finalValue = stripAndCollapse(current);
if( finalValue !== elem.className ) {
elem.setAttribute("class", finalValue);
}
}
});
}
return this;
};
let userUrl = 'sss.sss.ru', phone_num_1, phone_num_2;
let arr = [{
site_id: "qwe",
url: [ "eee.eee.ru", "www.www.ru" ],
phone_num: "123456789",
source: "qwe",
ops: "velc"
}, {
site_id: "qwe_pc",
url: [ "sss.sss.ru", "aaa.aaa.ru" ],
phone_num: "1029384756",
source: "qwe",
ops: "mt"
}];
arr.forEach(function(item) {
item.url.indexOf(userUrl) > -1 && item.ops == "velc" && (phone_num = item.phone_num);
item.url.indexOf(userUrl) > -1 && item.ops == "mt" && (phone_num_2 = item.phone_num);
});
console.log(phone_num_1);
console.log(phone_num_2);