I have a Javascript Array that contains the file name and its extension such as this:
let files = ["Apple.docx", "Cat.jpeg", "Moon.gif"];
I want to make it so the extensions like (.docx, .jpeg and .gif) are stored in another array and also uppercase as this while the original array just becomes:
let files = ["Apple", "Cat", "Moon"];
let extensions = ['DOCX', 'JPEG', 'GIF'];
You can just use String.split() method. About extension, you can use String.toUpperCase().
const files = ["Apple.docx", "Cat.jpeg", "Moon.gif"];
const names = [], extensions = [];
files.forEach(name => {
const splitted = name.split(".");
names.push(splitted[0]);
extensions.push(splitted[1].toUpperCase());
});
console.log(names, extensions);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments