Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - breaking a string into a formula

let's say I have an image, with this formula:

blabla.com/bla/twofive.hash.png

The above can be represented as a string in JavaScript.

I'd like to know how to build an array that will break every special sign (such as "." and "/"), and will contain something like this:

var arr =  ['blabla', 'com', 'bla', 'twofive', 'hash', 'png'];

so I can easily access any property of the array with a simple arr[number];

like image 606
RunningFromShia Avatar asked Apr 14 '26 04:04

RunningFromShia


1 Answers

simply try

"blabla.com/bla/twofive.hash.png".split(/[./]/) //outputs ["blabla", "com", "bla", "twofive", "hash", "png"]
like image 63
gurvinder372 Avatar answered Apr 15 '26 17:04

gurvinder372