getURLPath()函数用于将当前URL路径作为数组返回,其中每个项目都是URL路径的一部分。可以遍历此数组以分别访问路径的每个部分。
用法:
getURLPath()
参数:该函数不接受任何参数。
返回值:它返回路径组件的数组。
下面的示例说明了p5.js中的getURLPath()函数:
例:
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); 
}输出:
- 显示数组的内容:
   
- 在控制台中查看阵列:
   
参考: https://p5js.org/reference/#/p5/getURLPath
相关用法
- PHP next()用法及代码示例
- p5.js pow()用法及代码示例
- PHP Ds\Set xor()用法及代码示例
- p5.js second()用法及代码示例
- PHP each()用法及代码示例
- CSS url()用法及代码示例
- CSS var()用法及代码示例
- d3.js d3.map.set()用法及代码示例
- p5.js day()用法及代码示例
- d3.js d3.set.has()用法及代码示例
- PHP Ds\Map put()用法及代码示例
- p5.js value()用法及代码示例
注:本文由纯净天空筛选整理自sayantanm19大神的英文原创作品 p5.js | getURLPath() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
