const myObj = [
{object_id: 2, category_id: 2},
{object_id: 3, category_id: 2},
{object_id: 4, category_id: 1},
{object_id: 4, category_id: 2},
{object_id: 5, category_id: 1},
{object_id: 5, category_id: 2},
{object_id: 12, category_id: 1},
{object_id: 11, category_id: 1},
{object_id: 13, category_id: 1},
{object_id: 10, category_id: 1},
{object_id: 7, category_id: 3},
{object_id: 6, category_id: 3},
{object_id: 8, category_id: 3},
];
const myArr = [
{object_id: 2, category_id: 2},
{object_id: 3, category_id: 2},
{object_id: 4, category_id: 1},
{object_id: 4, category_id: 2},
{object_id: 5, category_id: 1},
{object_id: 5, category_id: 2},
{object_id: 12, category_id: 1},
{object_id: 11, category_id: 1},
{object_id: 13, category_id: 1},
{object_id: 10, category_id: 1},
{object_id: 7, category_id: 3},
{object_id: 6, category_id: 3},
{object_id: 8, category_id: 3},
];
var filtered = {};
function getObj (arr, cat_id) {
filtered[cat_id + ''] = [];
arr.forEach((item, i) => {
item['category_id'] == cat_id ? filtered[cat_id + ''].push(item['object_id']) : '';
})
}
getObj(myArr, 1);
console.log(filtered); // 1: [4,5,12,11,13,10]
var msg = "Error.0.Value : This is error for item 0.\r\nError.254.Value : This is error for item 1 and this item is exist.";
var result = {};
msg.split("\r\n").map((item, i) => { result["someinput[" +item.split(" : ")[0].match(/\d+/)[0]+ "]"] = item.split(" : ")[1]} )
console.log(result);
/*
{
someinput[0]:"This is error for item 0.",
someinput[254]:"This is error for item 1 and this item is exist."
}
*/
var s='from Moscow to Piter';
/* var s=' Moscow - Piter '; */
/* var s='из города Moscow в город Piter'; */
/* var s='из Moscow в Piter'; */
function findCities(str) {
var cities = [];
var strArray = str.split(' ');
for (var i=1; i<strArray.length; i++) {
if(strArray[i][0] === strArray[i][0].toUpperCase()) cities.push(strArray[i]);
}
return cities;
}
console.log(findCities(s)); // получаем на выходе ["Moscow", "Piter"]
var heroWid = document.getElementById("hero");
var heroObj = {
width: 150,
height: 100,
position: {
left: 1,
top: 2,
right: 3,
bottom: 4
},
next: 7
};
function update(el) {
el.style.cssText = 'width:' + heroObj.width + 'px; height: ' + heroObj.height + 'px;';
};
function heroCoord(el) {
var coord = el.getBoundingClientRect();
this.position = {
left: coord.left,
top: coord.top,
right: coord.right,
bottom: coord.bottom
};
return this;
};
update(heroWid); // устанавливаем параметры стиля блока
heroCoord.call(heroObj, heroWid); // обновляем значение объекта с данными блока
console.log(heroObj); // смотрим что получилось
e.preventDefault();
:this.target.disabled = true;
success
отдавайте в контекст события click
:this.target.disabled = false;
var counterId = document.body.innerHTML.match(/yaCounter[0-9]{1,}/)[0]
var objMetrika = window[counter];
/* На выходе функции getArray вы получите данные ответа на ajax-запрос */
var getArray = function(param){
var obj = {}
$.ajax({
type: "POST",
url: '/url/',
data: {"param": param},
complete: function(data){ // data - ответ полученный с сервера
obj = data; // записываем полученные данные data в ранее подготовленную переменную
}
});
return array; // возвращаем полученное значение ajax-запроса
}
props
компонента, а уже внутри него при помощи map
набирайте компонентов сколько необходимо.