Answer the question
In order to leave comments, you need to log in
Why doesn't the check for an empty array work?
I have this code:
$('.neispravnost').on('click', '.ns-blok', function(){
// some code...
goToNextStep ();
}
function goToNextStep (){
if(MyProblemArray.length != 0 || MySummArray.length != 0)
$('.step2-oformit').click( function(){
$('#tochki-step2').addClass('active');
$('#nav-step3').addClass('active');
$('#order-main').find('.step-wrap').removeClass('active');
$('#step3').addClass('active');
});
}
goToNextStep ()
works. I tried to do a check both inside the transition to the next step function, and in the function itself, where I work with an array:if(MyProblemArray.length != 0 || MySummArray.length != 0)
goToNextStep ();
// глобальные переменные
var MySummArray = [],
MyProblemArray = [],
novajasumm = 0,
datazena;
//код в функции
$(this).toggleClass('active');
datazena = $(this).attr('data-zena');
Problem = $(this).find('p').text();
var i = MySummArray.indexOf(Number(datazena));
var p = MyProblemArray.indexOf(Problem);
if (i != -1){
MySummArray.splice(i, 1);
} else {
$(this).each(function(i){
var numberu = $(this).attr('data-zena');
MySummArray.push(Number(numberu));
});
}
if (p != -1){
MyProblemArray.splice(p, 1);
} else {
$(this).each(function(i){
var newProblem = $(this).find('p').text();
MyProblemArray.push(newProblem);
});
}
console.log(MyProblemArray.join('; '));
var summitog = 0;
if(MySummArray.length != 0){
MySummArray.forEach(function(item, i, MySummArray) {
summitog += item;
});
} else {
summitog = 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question