📜  p5.js |反向()函数

📅  最后修改于: 2022-05-13 01:56:23.565000             🧑  作者: Mango

p5.js |反向()函数

p5.js 中的reverse()函数用于反转给定数组元素的顺序

句法:

reverse(Array)

参数:此函数接受一个参数数组,其元素将被反转。

返回值:它返回一个新的反转数组。

下面的程序说明了 p5.js 中的reverse()函数
示例:此示例使用 reverse()函数来反转给定数组元素的顺序

function setup() { 
  
    // Creating Canvas size
    createCanvas(500, 90); 
} 
  
function draw() { 
      
    // Set the background color 
    background(220); 
      
    // Initializing the arrays
    let Array1 = ['IT', 'CSE', 'ECE'];
        let Array2 = ['Civil', 'Mechanical'];
    
        // Calling to reverse() function.
        let Array3 = reverse(Array1);
        let Array4 = reverse(Array2);
      
    // Set the size of text 
    textSize(16); 
      
        // Set the text color 
    fill(color('red')); 
    
    // Getting new reversed array
    text("First reversed array is : "
      + Array3, 50, 30);
        text("Second reversed array is : " 
      + Array4, 50, 50);            
} 

输出:

参考: https://p5js.org/reference/#/p5/reverse