如何从数组的文件扩展名中删除点

时间:2018-10-10 20:08:44

标签: javascript

我有一个文件扩展名数组:

arr = [".png",".jpeg",".pdf",".json"......".jsx"]; // these file extensions are dynamic

每个文件扩展名前面都有一个点,我正尝试删除该点,以使o / p变为:

arr=["png","jpeg","pdf","json"......"jsx"] 

如何实现?

3 个答案:

答案 0 :(得分:1)

您可以像这样使用map函数:

[".png",".jpeg",".pdf",".json",".jsx"].map(e => e.substring(1))

这将返回:

["png", "jpeg", "pdf", "json", "jsx"]

答案 1 :(得分:1)

尝试使用地图!

  ID        CREATED_DATE           LAT          LON
    8289173 2018-10-02 16:52:54 -100.40871983   20.56314546
    8991287 2018-10-07 18:06:37 -100.40879701   20.56899227
    9077533 2018-10-08 11:55:31 -100.39687493   20.57479211
    9077534 2018-10-08 11:55:31 -100.36075875   20.58076244
    9077535 2018-10-08 11:55:31 -100.37852743   20.60783806
    9077536 2018-10-08 11:55:31 -100.36473954   20.61464554
    9077537 2018-10-08 11:55:31 -100.36424849   20.61501740
    9077538 2018-10-08 11:55:31 -100.40951731   20.60529101
    9227761 2018-10-09 18:10:00 -100.40851908   20.61148848
    9227762 2018-10-09 18:10:00 -100.40545509   20.61769963
    9227763 2018-10-09 18:10:00 -100.38008197   20.61098901
    9227764 2018-10-09 18:10:00 -100.36462022   20.61464574
    9227765 2018-10-09 18:10:00 -100.34415272   20.61327334
    9227766 2018-10-09 18:10:00 -100.33583425   20.61397514

答案 2 :(得分:0)

您应该通过替换'。'将数组映射到新数组。加上”,就像这样:

const arr = [".png",".jpeg",".pdf",".json"];
const newArray = arr.map(x => {
  return x.replace('.','');
})