setTimeout
не переполняет стек (статья, в которой затрагивается работа стэка, и setTimeout
в том числе), но нужно не забывать об использовании clearTimeout
, во избежание утечек памяти:let timeoutName = setTimeout(() => {
// Делаем что-то...
console.log('Hello, world!');
// Мы сделали все что нужно: очищаем память.
clearTimeout(timeoutName);
}, 5 * 1000);
function bbb() {
if(...) {
variable = true;
return;
}
SetTimeout(bbb, 2000);
}
array = [1, 2, 3, 4, 5]
a = 9
if (array.indexOf(a) == -1) {
// not found
}
array = [1, 2, 3, 4, 5]
a = 9
found = false;
for( i = 0; i < array.length; i++ ) {
if (array[i] = a) {
found = true;
console.log("if +");
}
}
if (!found) {
// not found
}
// human-friendly-concat.js
angular.module('yourModule', [])
.filter('humanFriendlyConcat', function() {
return function(input) {
input = input || [];
if (input.length === 0) {
return 'does not exist';
}
if (input.length === 1) {
return input[0];
}
if (input.length === 2) {
return input.join(' and ');
}
return input.slice(0, -1).join(', ') + ', and ' + input.slice(-1);
};
})
// template.html
<p>
This name <span ng-bind="name | humanFriendlyConcat"></span>.
</p>
И еще почему всегда первый элемент в опций виден как undefined ?
И если убрать ng-model то 1-ая опций undefined не будет.
If the viewValue of ngModel does not match any of the options, then the control will automatically add an "unknown" option, which it then removes when the mismatch is resolved.
<div class="container py-4">
<div class="row">
<div class="col-md-6">
<img class="img-fluid" src="" alt="">
</div>
<div class="col-md-3">
<img class="img-fluid" src="https://www.w3schools.com/w3images/fjords.jpg" alt="">
<img class="img-fluid" src="https://www.w3schools.com/w3images/fjords.jpg" alt="">
</div>
<div class="col-md-3">
<img class="img-fluid" src="https://www.w3schools.com/w3images/fjords.jpg" alt="">
<img class="img-fluid" src="https://www.w3schools.com/w3images/fjords.jpg" alt="">
</div>
</div>
</div>