(function() {
'use strict';
let btns = document.querySelectorAll('.btn');
for (let i = 0; i < btns.length; i++) {
btns[i].addEventListener('click', function() {
btns.forEach(btn => btn.classList.add('btn--class'));
});
}
})();
const array = [
{ name: 'Alex1', year: 13 },
{ name: 'Alex2', year: 14 },
{ name: 'Alex3', year: 15 },
{ name: 'Alex4', year: 16 },
{ name: 'Alex5', year: 17 }
];
const result = [];
let chunkSize = 2;
for (let i=0; i < array.length; i += chunkSize) {
const chunk = array.slice(i, i + chunkSize);
result.push(chunk);
}
console.log(result);
let obj = {
"viewport" : {
"key" : {
"lat" : 47,
"lng" : 39
},
"southwest" : {
"lat" : 47,
"lng" : 39
},
"one" : {
"keygen" : 47,
"lng" : 39
}
}
}
function deepSearch (object, key, predicate) {
if (object.hasOwnProperty(key)) {
return object
}
for (let i = 0; i < Object.keys(object).length; i++) {
if (typeof object[Object.keys(object)[i]] === 'object') {
let o = deepSearch(object[Object.keys(object)[i]], key)
if (o != null) return o
}
}
return null
}
const result = deepSearch(obj, 'keygen');
console.log(result); // {keygen: 47, lng: 39}