const merge = (a, b) => {
const combined = new Set([...Object.values(a), ...Object.values(b)]);
return Object.fromEntries(
[...combined.values()].map((value, index) => [index, value])
);
};
merge(
{ "0": 1, "1": 2, "2": 3 },
{ "0": 4, "1": 5, "2": 1 }
);
const general = {
style: ['palace', 'flat', 'house', 'bungalow', 'hotel'],
register: ['12:00', '13:00', '14:00'],
check: ['12:00', '13:00', '14:00'],
};
- function random(style, register , check) {
+ function random({ style, register, check }) {
- console.log(random(style, register , check));
+ console.log(random(general));
const pick = array => array[Math.floor(Math.random() * array.length)];
pick(['Apple', 'Orange']); // 'Apple' или 'Orange'
function random({ style, register , check }) {
return pick(style) + ', ' + pick(register) + ', ' + pick(check);
};
// Или так:
// const random = ({ style, register , check }) => `${pick(style)}, ${pick(register)}, ${pick(check)}`;
const openInNewTab = (base64Image) => {
const fixedBase64Image = base64Image.startsWith('data:image')
? base64Image
: `data:image/png;base64,${base64Image}`;
const image = new Image();
image.addEventListener('load', () => {
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
[canvas.width, canvas.height] = [image.width, image.height];
context.drawImage(image, 0, 0);
canvas.toBlob(blob => {
const link = document.createElement('a');
const url = URL.createObjectURL(blob);
[link.href, link.target] = [url, '_blank'];
link.addEventListener('click', () => {
setTimeout(() => {
URL.revokeObjectURL(url);
});
});
link.click();
});
});
image.src = fixedBase64Image;
};
openInNewTab('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==');
const store = new Proxy({
a: 50
}, {
set(target, property, value, receiver) {
console.log(`Поле <${property}> было обновлено. Новое значение:`, value);
return Reflect.set(target, property, value, receiver);
}
});
store.a = 10;
// Поле <a> было обновлено. Новое значение: 10
tabGroup = [
$('#calculator > main .threeing-selector:nth-child(1) .selectors li'),
$('#calculator > main .threeing-selector:nth-child(2) .selectors li')
];
...
let curTab = tabGroup.eq($(this).index());
butGroup = [
$('#calculator > main .threeing-selector:nth-child(1) .selectors li a'),
$('#calculator > main .threeing-selector:nth-child(2) .selectors li a')
],
...
let curButGroup = butGroup[i];
<?php
$filename = "data.json";
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");
if (file_exists($filename)) {
print(file_get_contents($filename));
} else {
print(json_encode([]));
}
?>
array.map(Object.values).flat(2);
array.map(entry => entry.elements).flat();
array.reduce((acc, entry) => [...acc, ...entry.elements], []);
- var out = ''
+ const responses = [];
- out += data;
+ responses.push(data);
await (await fetch(url)).json();
ok
, status
, statusText
, headers
и т. д. - var order = document.querySelector('popup_order');
+ var order = document.querySelector('.popup_order');
- $(document).on('focusin', '.search-auto', function () {
- $(this).keydown(function(e) {
+ $(document).ready(function () {
+ $('.search-auto').keydown(function (e) {