【问题标题】:Capitalise first letter in each string of an array and remove '_' character [duplicate]将数组的每个字符串中的第一个字母大写并删除“_”字符[重复]
【发布时间】:2020-02-19 08:39:13
【问题描述】:

所以我有一个看起来像这样的数组:

["image", "image_link", "images_carousel", "images_collection", "video", "video_carousel", "video_collection", "video_link"]

我需要将每个单词的第一个字母大写并删除一些单词之间的“_”。 我已经设法为一个字符串做到了,但我无法为这个数组得到它。一些帮助?谢谢。

【问题讨论】:

  • const newArr = yourArr.map(function(text) { /* change text here and return it */ });
  • 你能分享你目前的代码吗?
  • 请参阅第一个副本中的this specific 答案,了解实现您需要的最佳方法。

标签: javascript jquery


【解决方案1】:
yourArray.map(word => `${word.charAt[0].toUpperCase()}${word.slice(1)}`.replace(/_/g, " "));

【讨论】:

  • 请让 OP 知道这是如何解决她/他的问题的。
猜你喜欢
  • 1970-01-01
  • 2016-04-23
  • 1970-01-01
  • 2013-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-20
相关资源
最近更新 更多