Perform .join on value in array of objects

前端 未结 10 1524
囚心锁ツ
囚心锁ツ 2020-11-29 15:31

If I have an array of strings, I can use the .join() method to get a single string, with each element separated by commas, like so:

[\"Joe\", \"         


        
10条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 16:02

    I don't know if there's an easier way to do it without using an external library, but I personally love underscore.js which has tons of utilities for dealing with arrays, collections etc.

    With underscore you could do this easily with one line of code:

    _.pluck(arr, 'name').join(', ')

提交回复
热议问题