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

165
Visualizações
Is there way to pass values dynamically through array instead of using indexes

[image][1] [1]: https://i.stack.imgur.com/W7bNt.png

Right now it works like this:

1- when key's index 0 do this, 2- when key's index 1 do this, 3- when key's index 2 do this.

but I want to add min and max value for objectVal array that can fix (for stance key[min], n , key[max]) but nth values in between, like it can add new keys and values in slider dynamically instead of calling its indexs and adding new conditional operators.


const sliders = document.querySelectorAll(".allSliders");
let result = document.querySelector(".result");
let totalNumber = 0;
let values = [];
let sliderNums = [];

let objectVal = [
  {
   keys: [0, 500,1000],
    values: [0.0045,  0.0044,0.0043]
  }, 
  {
   keys: [0, 500,1000],
    values: [0.0045,  0.0044,0.0043]
  },
    {
   keys: [0, 500,1000],
    values: [0.0045,  0.0044,0.0043]
  },

]; 

sliders.forEach((sliderNumber, id) => {
  sliderNumber.addEventListener("input", () => {
    let action =
      objectVal[id].keys[3] - objectVal[id].keys[3];
    let maxLine = objectVal[id].keys[3] + action;
    let getInformation = maxLine - action * 0.666;
    sliderNumber.setAttribute("max", maxLine);

    let currentRange = parseInt(sliderNumber.value);
    sliderNums[id] = currentRange;

    function line(value, currentVal, obj) 
{
      values[id] = currentVal * obj;
      sliderNumber.nextElementSibling.querySelector(
        ".tooltiptext"
      ).textContent = `(${currentVal} * ${obj})`;
      sliderNumber.nextElementSibling.querySelector(".dollar").textContent =
       values[id].toFixed(2);
      }


    if (
      currentRange > objectVal[id].keys[0] &&
      currentRange <= objectVal[id].keys[3] ) 
      {
line(values[id], currentRange, objectVal[id].values[0])
      }
    else if (
      currentRange > objectVal[id].keys[3] &&
      currentRange <= objectVal[id].keys[3]
    ) {
     line(values[id], currentRange, objectVal[id].values[3])
    } 
    else {
      line(values[id], currentRange, objectVal[id].values[3])
    }```



about 4 years ago · Juan Pablo Isaza
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