p5.js | getURLParams() Function

The getURLParams() function is used to return the current URL parameters a JavaScript object, with each parameter as a separate member of the object.

Syntax:

getURLParams()

Parameters: This function does not accept any parameters.



Return Value: It returns an Object of the path parameters.

Below example illustrates the getURLParams() 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
  urlParamsObject = getURLParams();
  
  textSize(16);
    10, 20);
  
  text("The URL parameters are: ", 10, 60);
  
  text("Type parameter: " + urlParamsObject["type"], 10, 80);
  text("Height parameter: " + urlParamsObject.height, 10, 100);
  text("Width parameter: " + urlParamsObject.width, 10, 120);
  
  // display the array in the console
  console.log(urlParamsObject);
}

chevron_right


Output:

  • Displaying the properties of the object:
    path-obj-display
  • Viewing the object in the console:
    path-obj-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/getURLParams



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.