Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
Replace specific character from an Array of objects with another character in JS

I'm trying to replace character "/" with a blank space or a dash "-", but i can't seem to figure out how. I've tried some of the answers i've found here but it returns the same string. I have two set of arrays.

set A: elemnts = ["String1", "String2", "String3/"] set B gets each character of a s string from A to evaluate, an replace in case "/" is found.

 for(var i=0; i< elements.length; i++){
          arrayV = elements[i].value;
             for (var j=0; j <= arrayV.length; j++) {

                if(arrayV.charAt(j) === '/'){
arrayV[j] = "-";
                 }
   
    
                }
    
                elements[i]= arrayV;
       }

This is how i solved it (i learned something today):

var elements = document.getElementsByName("inputCont");

for(var i=0; i< elements.length; i++){

      var rString = elements[i].value;
  
         rString = rString.replace('/','-');
        
         elements[i].value = rString;
   }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In this example I use the function map() to create a new array and replace() to replace the character.

var elemnts = ["String1", "String2", "String3/"];

var result = elemnts.map(str => str.replace('/','-'));

console.log(result);

Update

OK, I missed the part about selecting the input elements. You can "cast" elements as an array and then iterate over that using map():

var elements = document.getElementsByName("inputCont");

var result = [...elements].map(elm => elm.value.replace('/', '-'));

console.log(result);
<form name="form01">
  <input type="text" name="inputCont" value="String" />
  <input type="text" name="inputCont" value="String" />
  <input type="text" name="inputCont" value="String/" />
</form>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda