Reseting an JavaScript Interval with different value?

Reseting an JavaScript Interval with different value?

Content Index :

Reseting an JavaScript Interval with different value?
Tag : javascript , By : cashshadow
Date : January 12 2021, 08:33 AM

will be helpful for those in need setInterval is appropriate to use when the delay is intended to be consistent.
Since your delay is meant to be different each time, it's probably better to use setTimeout here:
var times = [3000, 5000, 10000, 15000];

function start() {    
  var randTime = times[Math.floor(Math.random() * times.length)];
  setTimeout(start, randTime);


No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Is arr.length=0 better than arr=[] in javascript while reseting

Tag : javascript , By : Search Classroom
Date : March 29 2020, 07:55 AM
This might help you Yes, setting length to zero is a better solution since it truncates an existing array while arr=[] creates a new array and stores a reference to it in arr. It may happen that the old array isn't referenced any more and will be garbage collected. Hence, arr=[] may require an extra allocation and garbage collection compared to arr.length=0.
See this for the description of the special behavior of the length property on which this relies.

Why is my form still reseting when I submit with JavaScript?

Tag : javascript , By : platformNomad
Date : March 29 2020, 07:55 AM
I hope this helps you . I am submitting a form with JavaScript. , Please add return false in function
function submitForm() {

    var usersRoles = new Array;
    jQuery("#dualSelectRoles2 option").each(function () {

    var model = new Object();
    model.userId = jQuery('#selectUser').val();
    model.rolesList = usersRoles;

    console.log('model: ' + 'user: ' + model.userId + 'roles: ' + model.rolesList);
    console.log('JSON: ' + JSON.stringify(model));

        type: "POST",
        url: "@Url.Action("AddUser")",
        dataType: "json",
        contentType: "application/json",
        data: JSON.stringify(model),
        success: function (data) { showSuccessMessage(data); },
        failure: function (errMsg) {
 return false;

javascript timer keeps reseting too soon (not working)

Tag : javascript , By : aspitzer
Date : March 29 2020, 07:55 AM
Does that help There is a small flaw in your logic.
During the countdown initialization your doing
seconds = secs || 60;
function countdownInit(mins, secs) {
  seconds = secs || 60;
  minutes = mins;
  console.log(mins + 'min ' + seconds + 'sec');

countdownInit(1, 30) // ok
// 1min 30sec

countdownInit(1) // not ok
// 1min 60sec
// thats 2 minutes
function countdown(mins, secs) {
    seconds = secs;
    minutes = mins;
    // if secs is 0 or uninitialized we set seconds to 60 and decrement the minutes
    if(!secs) {
      seconds = 60;

    function tick() {
        var counter = document.getElementById("timer");
        // we use minutes instead of current_minutes in order to show what's really in our variables
        counter.innerHTML =
          minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);

        // rest of code
    // rest of code

Why does my javascript var value keep reseting?

Tag : javascript , By : techthumb
Date : March 29 2020, 07:55 AM
Does that help You var is not resetting, actually the page is reloading. You can avoid that in many different ways:
function show(event, choice){
  var user=choice;
  if ( user == 1) {
        document.getElementById('one').style = "display:block";
        document.getElementById('two').style ="display:none";
        document.getElementById('three').style ="display:none";
      else if ( user == 2) {
        document.getElementById('one').style = "display:none";
        document.getElementById('two').style ="display:block";
        document.getElementById('three').style ="display:none";
      else if ( user == 3) {
        document.getElementById('one').style = "display:none";
        document.getElementById('two').style ="display:none";
        document.getElementById('three').style ="display:block";
  width: 150px;
  height: 100px;
  width: 150px;
  height: 100px;
  width: 150px;
  height: 100px;
<a class="nav-link" href="" onclick="show(event, 1)">HOME</a>
<a class="nav-link" href="" onclick="show(event, 2)">ABOUT ME</a>       
<a class="nav-link" href="" onclick="show(event,3)">CONTACT</a>
<div class="div1" id="one"></div>
<div class="div2" id="two"></div>
<div class="div3" id="three"></div>
<a href="#one">

angular 6 reseting one array object is reseting another as well

Tag : angular , By : mckasty
Date : March 29 2020, 07:55 AM
I wish did fix the issue. As stated here:
this.processedItems = [];
Related Posts Related QUESTIONS :
  • How to auto input MySQL data (input column 1 data to auto input column 2 data with same column) in php?
  • Appending to Datalist Via Javascript
  • Customizing Material-UI Components with Styled-Components
  • Populate elements with class name using Javascript
  • How to execute promises in batches (first resolving 10, then next 10 and so on)
  • Maximo JS automation script: "importPackage" is not defined
  • How to surround selected text inside textarea with <em> on key combination CTRL+i?
  • Your configured registry does not support audit requests ~ On npm audit
  • What's the Angular equivalent of Vue <slot/>?
  • Iconify icon not updating when "data-icon" set with setAttribute()
  • Javascript newbie stuck with XMLHttpRequest return data
  • How to add obj to to state in my example Redux React
  • Loading "grunt-karma.js" tasks...ERROR >> SyntaxError: Unexpected identifier
  • Why do I get log is not defined
  • get the multiple index of the same string
  • How can I iterate over an Array object by using For IN or FOR OF
  • Launch local executable from web browser
  • How to prepare array of json objects to d3 hierarchical tree structure
  • VueJS - event emitted - show HTML before other calculations
  • Export SASS/SCSS variables to Javascript without exporting them to CSS
  • How to attach an event handler only once continuously
  • How to make button open a link in new tab in JavaScript?
  • Find range from the javascript object
  • How can I use my jQuery code as JavaScript?
  • How to show 5 images in a 2 row slider with bxslider
  • How to convert stream into variables in typescript
  • Three.js custom shader error on Chrome GL_INVALID_OPERATION: Active draw buffers with missing fragment shader outputs
  • My JavaScript doesn't work. How can I solve this problem?
  • Why is this async function is running synchronously?
  • Get updated variable from within react hook before return
  • I want to show all image preview but whenever I upload a new one the old one is gone
  • Would I be able to give access to specific electron APIs safely?
  • Why several clicks fire for each instance of a Class?
  • cant grab value from div using attr()
  • Make web service not accessible by browser?
  • Select DOM elements within template
  • How to customize angular ui-grid row background color?
  • Binding data in two respective $scope in AngularJS, how?
  • react put some props after import class
  • Variable is distributed among same components
  • switch class in jQuery/JavaScript for active/inactive state
  • How To Track Outbound Clicks Using Javascript
  • How to get total seconds elapsed since the beginning of the month?
  • Protractor: Stale element reference at "browser.wait(EC.visibilityOf(confDial), FIFTY_SECONDS);"
  • Access to an array inside an object
  • Learning Angular for the first time - version 2 or 4?
  • Rendering RSS feed (XML) in React with jquery, why do object values parsed from the feed seem empty?
  • Node.js xml2js http.request tag matching
  • applying texture to custom plane geometry in Threejs
  • How do I pass an Event as a function parameter in HTML written inside JavaScript variable?
  • Interface of object parameter with default value and default property
  • Does using try / catch rather than `.catch` observable operator with XHR requests reduce performance?
  • In IE11 background colors not working on printing
  • TypeScript interface signature "(): string"
  • Is synchronous XMLHttpRequest supported in Internet Explorer 10 and 11?
  • Axios function not returning any values with js
  • How to use firestore TIMESTAMP to create time-stamp in JavaScript
  • Instantiate subclass without constructing
  • Outputing a created object in javascript to a server side JSON file
  • Transition the numeric labels in a bar chart
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com