var items = [
{
id: "1",
name: "тест1",
parents_names: ["Московская", "Орехово-Зуевский"],
parents_levels: [1, 3]
},
{
id: "2",
name: "Тест2",
parents_names: ["Карелия", "Прионежский", "Центральный"],
parents_levels: [1, 3, 7]
},
{
id: "3",
name: "Тест3",
parents_names: ["Санкт-Питер"],
parents_levels: [1]
},
];
var data = {
1 : 'region',
3 : 'area',
7 : 'street'
}
console.log(items.map(function(i) {
i.parents_levels.forEach(function(p, ind) {
i[data[p]] = i.parents_names[ind];
})
delete i.parents_names;
delete i.parents_levels;
return i;
}));
console.log(/name=([\"\'])([^\"\']+)\1/.exec('<span name="two">text</span>')[2]);
function _getAttr (str, attr) {
return new RegExp(attr + "\s*=\s*([\"\'])([^\"\']+)\\1").exec(str)[2];
}
console.log(_getAttr('<span name="two">text</span>', 'name'));
function Equipment() {
const Bag = [];
function addTools() {
for (var i=0; i < tools; i++) {
Bag.push(tools.item1)
}
Object.assign(Bag, new tools);
console.log('=== ', Bag.item2)
}
addTools()
}
function tools() {
this.item1 = {
name: "item1",
price: 5,
count: 10
};
this.item2 = {
name: "item2",
price: 15,
count: 20
};
this.item3 = {
name: "item3",
price: 20,
count: 30
};
this.item4 = {
name: "item4",
price: 30,
count: 40
};
this.item5 = {
name: "item5",
price: 40,
count: 50
};
}
Equipment();
cookies({
filterShow: 0
}, {
expires: 3600, // время жизни в секундах
path: '/'
});
if (obj instanceof Array) console.log('obj isArray!');