javascript forEach statement

Asked 2 years ago, Updated 2 years ago, 19 views

What you want to achieve

I want the shop ID to be included in the array and displayed in the string \A/shop/${shopId*array0}/$|\A/shop/${shopId*array1}/$|\A/shop/${shopId*array0}/$...

const shopId=[263,966,5439,5478,5613,5368,169,1499,42382,4807,4808,5244];

salonId.forEach((salonId)=>{
  console.log(`\\A/shop/${shopId}/$`);
});

I would like to use a "|" (pipe) to connect the string from the first array after executing it with each as above, but I don't know how to do it.
Can someone teach me?

javascript

2022-09-29 21:45

1 Answers

If you want forEach, you will need another array containing the results of the action in forEach.In the first place, map() would be more appropriate.

shopId.map(s=>`\\A/shop/${s}/$`).join('|');


2022-09-29 21:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.