-1
 Var a = "837297,870895"
 Var b = "37297,36664"

OutPut = "837297_37297,870895_36664

I tried multiple script but does not working

4
  • 2
    split and a loop. Show what you attempted Commented Feb 14, 2022 at 20:59
  • 2
    JavaScript is case sensitive Var is not var (lowercase) Commented Feb 14, 2022 at 21:01
  • Your question is not combining arrays. Your question is about replacing the comma with an underscore and then concatenating the strings with a comma between. Commented Feb 14, 2022 at 21:33
  • Does this answer your question? replace one string with another in javascript and Joining two strings with a comma and space between them Commented Feb 14, 2022 at 21:38

2 Answers 2

0

You can split and map the splitted array as such:

var a = "837297,870895" 
var b = "37297,36664"

var output = a.split(',').map((e,i)=> e+"_"+b.split(',')[i])
console.log(output.toString())

For ES2015 or lower

var a = "837297,870895" 
var b = "37297,36664"

var output = a.split(',').map(function(e,i){return e+"_"+b.split(',')[i]})
console.log(output.toString())

Sign up to request clarification or add additional context in comments.

4 Comments

@jaivBhp Getting error - Error at line 6, character 31: This language feature is only supported for ECMASCRIPT_2015 mode or better: arrow function.
Rahul, it's 2022. Maybe time to update your development profile.
Yes but you can also not use the arrow function. But i suggest to update you javascript to latest ecmascript
Better yet, understand what the functions do, so that you can do them without the specific functionality available.
-1

You can start by converting the two strings (lists) into arrays using .map() and .split() methods. Then use .map() and .join() methods to produce the desired string (list):

const a = "837297,870895";
const b = "37297,36664";

const [c,d] = [a,b].map(e => e.split(','));

const output = c.map((e,i) => `${e}_${d[i]}`).join();

console.log( output );

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.