Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array values to a string in loop

Tags:

javascript

I have an object (key value pair) looks like this

enter image description here

I want to get a string of '[100000025]/[100000013]'

I can't use var str = OBJ[0].PC + OBJ[1].PC (which gives me '100000025100000013') because I need the bracket structure. The number of items can vary.

Added >> Can it be done without using arrow function?

like image 904
The Tag Manager Avatar asked Sep 17 '26 18:09

The Tag Manager


1 Answers

 const string = array.map(({PC}) => `[${PC}]`).join('/')

You could map every string to the string wrapped in brackets, then join that by slashes.

like image 122
Puwka Avatar answered Sep 19 '26 06:09

Puwka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!