The getURLPath() function is used to return the current URL path as an array, with each item being a portion of the URL path. This array can be traversed to access every portion of the path separately.
Syntax:
getURLPath()
Parameters: This function does not accept any parameters.
Return Value: It returns an array of the path components.
Below example illustrates the getURLPath() function in p5.js:
Example:
function setup() {
createCanvas(500, 200);
urlPathArray = getURLPath();
textSize(16);
text( "The URL paths are: " , 10, 40);
for (let i = 0; i < urlPathArray.length; i++) {
text( '- ' + urlPathArray[i], 10, i * 15 + 60);
}
console.log(urlPathArray);
}
|
Output:
- Displaying the contents of the array:

- Viewing the array in the console:

Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
Reference: https://p5js.org/reference/#/p5/getURLPath