p5.js | getURLPath() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
  createCanvas(500, 200);
  
  // get the url path as array
  urlPathArray = getURLPath();
  
  textSize(16);
  
  text("The URL is: http://example.com/path1/path2/path3/index.html", 10, 20);
  
  text("The URL paths are: ", 10, 40);
  // loop through the array to display
  // the array items
  for (let i = 0; i < urlPathArray.length; i++) {
    text('- ' + urlPathArray[i], 10, i * 15 + 60);
  }
  
  // display the array in the console
  console.log(urlPathArray);
}

chevron_right


Output:

  • Displaying the contents of the array:
    path-array-display
  • Viewing the array in the console:
    path-array-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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.