const moves = [];
...
moves.push(JSON.stringify(jsonmove));
...
const datamove = "[\n" + moves.join(",\n") + "\n]";
const moves = [];
...
moves.push(jsonmove);
...
const datamove = JSON.stringify(moves);
document.addEventListener('click', e => {
const btn = e.target.closest('.more-btn');
for (const n of document.querySelectorAll('.more-btn')) {
n.classList.toggle('active', n === btn && !n.classList.contains('active'));
}
// или
document.querySelectorAll('.more-btn').forEach(function(n) {
n.classList[n === this ? 'toggle' : 'remove']('active');
}, e.target.closest('.more-btn'));
});
const f = i => {
console.log(i);
};
for (let i = 0; i < 5; i++) {
setTimeout(f, 1000, i);
}
<button type="submit" id='btn'>Отправить</button>
document.querySelector("#form").addEventListener("submit",function(e){
let isValid = true;
//Какие-то проверки
if(!isValid)
e.preventDefault();//отмена
});
<?php
$results = [
['order_id' => 'first', 'id'=>1],
['order_id' => 'second', 'id'=>4],
['order_id' => 'third', 'id'=>7]
];
$filtered = array_filter(
$results,
function($el) {
return $el['id'] != 4;
}
);
var_export($filtered);
``
) используются не только в виде строк, но и как аргументы функции. Иными словами из-за такое действие преттиера предотвращает вот эту ситуацию:console.log()
`${123}dsa`
// =
console.log()`${123}dsa`
console.log
, которая в свою очередь вернёт андефайнд, а далее андефайнд будет использован как функция, что приведёт к:Uncaught TypeError: console.log() is not a function
console.log()
;`${123}dsa`
будет идентична такой:console.log();
`${123}dsa`;
и никакой ошибки не будет. const expression = /{{\s+?(\w+)\s+?}}/g;
const pasteParams = (string, params) => {
return string.replace(expression, (match, key) => key in params
? params[key]
: key
);
};
pasteParams('<ul class="{{ className }}"></ul>', {
className: 'my-class'
});
const flatArr = arr.flatMap(n => Array.isArray(n.DOP) ? n.DOP : []);
// или
const flatArr = Array.prototype.concat.apply([], arr.map(n => n.DOP ?? []));
// или
const flatArr = arr.reduce((acc, n) => (n.DOP && acc.push(...n.DOP), acc), []);
const unique = Object.values(Object.fromEntries(flatArr.map(n => [ n.NAME, n ])));
// или
const unique = flatArr.filter(function({ NAME: n }) {
return !(this[n] = this.hasOwnProperty(n));
}, {});
// или
const unique = flatArr.filter((n, i, a) => n === a.find(m => m.NAME === n.NAME));
this.setState(({ items }) => ({
items: items.map((n, i) => ({ ...n, id: i })),
}));
state = {
items: this.props.items.map((n, i) => ({ ...n, id: i })),
}
computed: {
grouped() {
return this.arr.reduce((acc, n) => ((acc[n.group] ??= []).push(n), acc), {});
},
},
<v-expansion-panels>
<v-expansion-panel v-for="(items, groupName) in grouped">
<v-expansion-panel-header>{{ groupName }}</v-expansion-panel-header>
<v-expansion-panel-content>
<div v-for="n in items">{{ n.name }}</div>
</v-expansion-panel-content>
</v-expansion-panel>
</v-expansion-panels>