Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!