gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 01:36:54 27 4
gpt4 key购买 nike

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

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

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

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

如何实现这一点?

最佳答案

您应该通过替换 '.' 将数组映射到新数组中与 '',像这样:

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

关于javascript - 如何从数组中的文件扩展名中删除点 - Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52748026/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com