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

212
Vistas
How to Remove string after string replace

For that code below the output of ins (lets assume the value of keys are summer, spring, fall, winter) is:

['req.body.summer, req.body.spring, req.body.fall, req.body.winter']

What i want is remove the string after the replace command, so i can insert it to my SQLite query. So the output must be:

[req.body.summer, req.body.spring, req.body.fall, req.body.winter]

Im just new into programming so please bear with me. Thank you!

var arr = '';

Object.keys(input).forEach(function(key) {
  arr += 'req.body.' + key + ', ';
});

var ins = [arr.replace(/,\s*$/, '')];

console.log(ins);
about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Try this...

Just declare arr as an array and Push the values into it.

var arr = [];
var input = ['summer', 'spring', 'fall', 'winter'];
(input).forEach(function(key,value) {
  arr.push('req.body.' + key);
});


console.log(arr);

about 4 years ago · Santiago Trujillo Denunciar

0

If the input is an array of strings, like 'summer', then do this:

var arr = input.map(key => req.body[key]);

// Sample input
var input = ['summer', 'spring', 'fall', 'winter'];

// Sample req:
var req = {
    body: {
        summer: 'sun',
        spring: 'birds',
        fall: 'leaves',
        winter: 'snow'
    }
};

var arr = input.map(key => req.body[key]);

console.log(arr);

If you prefer the function syntax instead of =>:

var arr = input.map(function (key) {
    return req.body[key];
});
about 4 years ago · Santiago Trujillo Denunciar

0

What you are looking for an Array of String Objects

var arr = new Array() ;var input= { 'spring':'a','summer': 'b'}
    Object.keys(input).forEach(function(key) {
      arr.push('req.body.' + key);
    });
    console.log(arr); // Prints ["req.body.spring", "req.body.summer"]

about 4 years ago · Santiago Trujillo 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