JavaScript
19
Вклад в тег
array.forEach((element, index, array) => {}) // 2 и 3 необязательные
array.forEach((element) => element.balance.startsWith("$1") && console.log(element.balance))
array.forEach(({ balance }) => balance.startsWith("$1") && console.log(balance))
function findBalance (array) {
return array.filter(({ balance }) => balance.startsWith("$1"))
}
console.log(findBalance(users))
// Вместо
{ balance: "$1,000.57" }
// Сделать так
{
balanceAmount: 1000.57,
balanceCurrency: '$'
}
// Или так
{
balance: {
amount: 1000.57,
currency: '$'
}
}
const balance = {
amount: 1768.67,
currency: '$'
}
console.log(`${balance.currency}${balance.amount.toLocaleString('en-EN')}`);
const balance = {
amount: 1768.67,
currency: 'USD'
}
console.log(balance.amount.toLocaleString('en-EN', { style: 'currency', currency: balance.currency }));
const sum = (...args) => (
args.flat().reduce((acc, next) => acc += next, 0)
)
function sum(a1, a2) {
let result = 0
for (let i = 0; i < a1.length; i++) {
result += a1[i] + a2[i]
}
return result
}