<a class="on" href="javascript:;">Включить</a>
<a class="off" href="javascript:;">Выключить</a>
<div class="text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequatur, molestiae!
</div>
.text {
display: none;
}
.on {
&.is-active {
color: green;
}
}
.off {
&.is-active {
color: grey;
}
}
$on = $('.on');
$off = $('.off');
$text = $('.text');
active = 'is-active';
$on.click(function() {
$text.fadeIn(300);
$on.addClass(active);
$off.removeClass(active);
})
$off.click(function() {
$text.fadeOut(300);
$on.removeClass(active);
$off.addClass(active);
})
var obj = {CHF: 9095, USD: 45966, UAH: 4324};
var arr = [];
for (var key in obj) {
arr.push({amount: key, currency: obj[key]});
}
console.log(arr);
var jsonObj = $.parseJSON('[{"id":1, "amount":123, "currency" : "CHF"},{"id":2, "amount":321, "currency" : "USD"},{"id":3, "amount":4324, "currency" : "UAH"},{"id":4, "amount":45645, "currency" : "USD"},{"id":5, "amount":8972, "currency" : "CHF"}]');
var data = {};
$.each(jsonObj, function(index, value){
if(!data.hasOwnProperty(value.currency)){
data[value.currency] = value.amount;
}else{
data[value.currency] = data[value.currency] + parseInt(value.amount);
}
});
var data = [{'id': 1, 'amount': 123, 'currency': 'CHF'}, {'id': 2, 'amount': 321, 'currency': 'USD'}, {
'id': 3,
'amount': 4324,
'currency': 'UAH'
}, {'id': 4, 'amount': 45645, 'currency': 'USD'}, {'id': 5, 'amount': 8972, 'currency': 'CHF'}];
var newData = [];
for (i = 0; i < data.length; ++i) {
if (typeof newData[data[i]['currency']] == 'undefined')
newData[data[i]['currency']] = 0;
newData[data[i]['currency']] += data[i]['amount'];
}
for (var key in newData) {
console.log(key + ' ' + newData[key]);
}
var arr = [{'id':1, 'amount':123, 'currency' : 'CHF'},{'id':2, 'amount':321, 'currency' : 'USD'},{'id':3, 'amount':4324, 'currency' : 'UAH'},{'id':4, 'amount':45645, 'currency' : 'USD'},{'id':5, 'amount':8972, 'currency' : 'CHF'}];
var result = {};
arr.forEach(function(item){
if(!result.hasOwnProperty(item.currency))
result[item.currency] = 0;
result[item.currency] += item.amount;
});
console.log(result)
//Object {CHF: 9095, USD: 45966, UAH: 4324}
$(function(){
$("#id-input").mask("99 999");
});