// комментарий
/* CSS-комментарий */
const asyncForEach = (data, callback) =>
Array.prototype.reduce.call(
data,
(promise, n, i, a) => promise.then(() => callback(n, i, a)),
Promise.resolve()
).then(() => {});
// или
async function asyncForEach(data, callback) {
for (let i = 0; i < data.length; i++) {
await callback(data[i], i, data);
}
}
asyncForEach(
document.querySelectorAll('li'),
li => new Promise(r => setTimeout(() => r(console.log(li.textContent)), 1000))
);
const obj = arr.find(n => n.id === newObj.id);
if (obj) {
Object.assign(obj, newObj);
} else {
arr.push(newObj);
}
const psList = require('ps-list');
(async () => {
console.log(await psList());
//=> [{pid: 3213, name: 'node', cmd: 'node test.js', ppid: 1, uid: 501, cpu: 0.1, memory: 1.5}, …]
})();