Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
Mostrar valor de nombre basado en días específicos

Tengo una entrada como esta: var names = ["Ram","Shyam","Neel","Nik"]; Necesito mostrar estos nombres en una tabla que se etiquetará en Fin de semana, por ejemplo:

Tabla de nombres

Puntos: -Esta tabla seguirá generando los nombres de los fines de semana mes a mes. Aquí está el código probado pero no está generando ningún resultado. No estoy seguro de qué error he cometido.

Soy bastante nuevo en JS y probé el siguiente código. Necesito ayuda aquí: https://www.jdoodle.com/h/1IW

Aquí está el fragmento de código:

 const is_weekend = function(dt){ if(dt.getDay() == 6 || dt.getDay() == 0) return true; else false; } var array = ["Tom","Taylor","Nick","John"]; var currArrIndex = 0; var start = new Date(); //current date var end = new Date(start.getFullYear(), start.getMonth()+1, 0); //last date of the month var rows = Array(); var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"] var currDate = start; console.log(currDate); while(currDate <= end){ //alert(currDate); console.log(currDate); if(is_weekend(currDate)){ //if the date is a weekend date let dayName = days[currDate.getDay()]; //get week day of the current date let rowElement = { name : array[currArrIndex], //set one of the names from array from first to last day : dayName, date : currDate.toLocaleDateString() } rows.push(rowElement); if(currDate.getDay() == 0){ //change after every week currArrIndex ++; //current index array name is already assigned to last weekend, hence move to next array name currArrIndex %= array.length; //if current index goes beyond array length resign to 0 } } var newDate = currDate.setDate(currDate.getDate() + 1); currDate = new Date(newDate); } var html = "<table border='1|1'>"; for (var i = 0; i < rows.length; i++) { let htmlElement = ` <tr> <td>${rows[i].name}</td> <td>${rows[i].day}</td> <td>${rows[i].date}</td> </tr>`; html+=htmlElement; } html+="</table>"; document.getElementById("box").innerHTML = html;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Escribí similar a esto antes. Lo edité de acuerdo con su salida. Esperemos que funcione.

 var list =[]; var persons = ["Ram","Shyam","Neel","isa","test","caglar"]; var start = new Date(); var end = new Date("2021-12-02"); var rows = []; function test(){ var fillCount = 0; var listCount = 0; for (var d = start; d <= end; d.setDate(d.getDate() + 1)) { if(listCount == persons.length) break; var currdate = new Date(d); var dayOfWeek = currdate.getDay(); if((dayOfWeek === 6) || (dayOfWeek === 0)) // 6 = Saturday, 0 = Sunday { if(fillCount < 2) { console.log({"Dates": currdate.toLocaleDateString(), "Name": persons[listCount], "Day" : currdate.toLocaleDateString("en-EN", { weekday: 'long' }) }); list.push({"Dates": currdate.toLocaleDateString(), "Name": persons[listCount], "Day" : currdate.toLocaleDateString("en-EN", { weekday: 'long' }) }); fillCount++; if(fillCount == 2) { fillCount = 0; listCount++; } } } } }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda