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

213
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 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