Дмитрий Луценко, как вариант...
const obj = { 'reno': '$15000', 'audi': '$20000', 'bmw': '$30000', 'peogeot': '18000$' } const s = Object.values(obj).reduce((val, el) => val += value(el), 0) alert(s) // Вернет число function value(str) { const i = str.indexOf('$') if (i === -1) return +str return +(i ? str.substring(0, i) : str.substring(1)) } |
ок, спасибо ребята!
|
:) :write:
<script src="https://cdnjs.cloudflare.com/ajax/libs/collect.js/4.34.0/collect.min.js"></script> <script> const objCars = { 'reno': '$15000', 'audi': '$20000', 'bmw': '$30000', 'peogeot': '18000$' } const total = collect(objCars).sum(value => value.replace(/\D+/g, '')); alert(total); </script> |
Цитата:
|
Часовой пояс GMT +3, время: 06:05. |