var cart = {};
function addToCart() {
var articul = this.dataset.id;
cart[articul] = 1;
console.log(cart);
}
document.getElementById('addToCart').addEventListener('click', addToCart);
function isObject(item) {
return (typeof item === "object" && !Array.isArray(item) && item !== null);
}
preg_match('/^(.+)\ \((.+)\)/', $name, $matches);
array_shift($matches);
$matches; /*Array
(
[0] => Ньютон И.И.
[1] => Тринити коледж, Кембридж
)*/
$name = "Ньютон И.И. (Тринити коледж, Кембридж)";
$name = substr($name, 0, -1);
$result = explode(' (', $name);
print_r($result);
const getChunks = (arr, chunkSize) =>
Array.from(
{ length: Math.ceil(arr.length / chunkSize) },
(n, i) => arr.slice(i * chunkSize, (i + 1) * chunkSize)
);
// или
const getChunks = (arr, chunkSize) =>
arr.reduce((acc, n, i) => (
i = i / chunkSize | 0,
(acc[i] = acc[i] || []).push(n),
acc
), []);
// или
const getChunks = (arr, chunkSize) =>
arr.reduce((acc, n, i) => (
(i % chunkSize) || acc.push([]),
acc[acc.length - 1].push(n),
acc
), []);
const arr = [...Array(50).keys()];
const chunks = getChunks(arr, 7);
А ведь не должен приходить, я же не нажимал кнопку "Отправить"
function get_values_by_keys($input, $keys) {
return array_map(function($item) use ($input) {
return $input[$item];
}, $keys);
}
const calculateAndDisplayRoute = callback => new Promise((resolve, reject) => {
var waypts = [];
return this.directionsService.route({
origin: "Аэропорт, Республика Башкортостан, Россия",
destination: $('#address_to').val(),
waypoints: waypts,
optimizeWaypoints: true,
travelMode: 'DRIVING'
}, (response, status) => {
if (status === 'OK') {
resolve(callback(response, status));
}
reject(status);
});
});
async function run() {
try {
await calculateAndDisplayRoute((response, status) => {
console.log(status);
result = status;
this.directionsDisplay.setDirections(response);
return true;
});
console.log(result);
} catch (e) {
console.log(e);
}
}
if (empty($num1) || empty($num2)) {
$num1 = int($_POST['num1']); // не верно
$num1 = (int) $_POST['num1']; //верно
if (isset($_POST['num1']) && isset($_POST['num2']) && isset($_POST['operator'])) {
$num1 = intval($_POST['num1']);
$num2 = intval($_POST['num2']);
$operator = $_POST['operator'];
switch ($operator) {
case '+':
echo $num1 + $num2;
break;
case '-':
echo $num1 - $num2;
break;
}
} else {
echo "Что-то не передано!";
}
target.appendChild(content)
Свойство innerHTML многих типов элементов, включая body или html, могут быть возвращены или перемещены. Это может так же быть использовано для просмотра кода страницы, которая была изменена динамически: