const total = array.reduce((acc, entry) => {
acc += entry.price;
return acc;
}, 0);
The storage event of the Window interface fires when a storage area (localStorage or sessionStorage) has been modified in the context of another document.
color : 'rgba(' + '255, 255, 255' + ',' + 0.4 + ')'
canvas
в другой цвет, либо в самом JS. cmd
. Если gulp
установлен в devDependencies
, тогда через npm scripts
. [
{
type: 'Button',
props: {
label: 'Ok'
}
},
{
type: 'Card',
props: {
label: 'News',
Image: 'request...'
}
},
{
type: 'TextInput',
props: {
placeholder: 'Hello'
}
}
];
render
сделать так:{{page.map(element => <element.type {...element.props} />)}}
li:empty {
display: none;
}
document.querySelectorAll('li:empty').forEach(element => element.remove());
document.querySelectorAll('li').forEach(element => {
if (element.childNodes.length === 0) {
element.remove();
}
});
var arr = [
{
name: 'Alex',
data: {
role: '1'
},
childItems: ['Bob', 'Alice']
},
{
name: 'Kristine',
data: {
role: '2'
},
childItems: ['Kate', 'Morgan']
}
];
function copy(object) {
var root = {};
Object.keys(object).forEach(function (key) {
var branch = object[key];
if (typeof branch === 'object' && !(branch instanceof Array)) {
root[key] = copy(branch);
} else {
root[key] = branch;
}
});
return root;
}
var newArr = arr.reduce(function (acc, entry) {
var clonedEntry = copy(entry);
delete(clonedEntry.childItems);
acc.push(clonedEntry);
return acc;
}, []);
console.log(arr); // [{ name: 'Alex', data: { role: '1' }, childItems: [ 'Bob', 'Alice' ] }, { name: 'Kristine', data: { role: '2' }, childItems: [ 'Kate', 'Morgan' ] }]
console.log(newArr); // [{ name: 'Alex', data: { role: '1' } }, { name: 'Kristine', data: { role: '2' } }]
copy
сделать для разных типов. [...new Set(array)]
.[document.querySelector('div'), document.querySelector('div')]; // [div#TMpanel, div#TMpanel]
[...new Set([document.querySelector('div'), document.querySelector('div')])]; // [div#TMpanel]
.getBoundingClientRect()
и т. д.