javascript - Combine each element of a string with the second string -


i have 2 strings

[a,b,c]  //there number of items in these 2 strings [x,y,z] 

i want output this

a[x,y,z] b[x,y,z] c[x,y,z] 

not quite able logic output.

to array use map()

var s1 = '[a,b,c]',    s2 = '[x,y,z]';  console.log(    s1    .slice(1, -1) // remove `[` , `]`    .split(',') // split based on `,`    .map(function(a) { // iterate , generate array      return + s2;    })  )


to string use reduce()

var s1 = '[a,b,c]',    s2 = '[x,y,z]';  console.log(    s1    .slice(1, -1) // remove `[` , `]`    .split(',') // split based on `,`    .reduce(function(a, b) { // iterate , generate string      return + (a.length ? '\n' : ' ') + b + s2;    }, '')  )


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -