var array1 = [1, 2, 3];
var array2 = [4, 5, 6];
var array3 = array1.concat(array2);
// After that `array3` will be `[1, 2, 3, 4, 5, 6]`.
  • There is func.apply() from object to fill func() with parameters.
  • Here is the example codes that will print "hello world" in the console.
var args = ["hello", "world"];
function test (_arg1, _arg2) { console.log(_arg1 + " " + _arg2); }
test.apply(this, args);
  • This is the reference for func.apply(), https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply.
  • In P5JS use strokeWeight() to adjust stroke thickness. For example strokeWeight(10) will set the next shape as 10 pixels thick.
  • In P5JS use cursor() to change the pointer type into browser (then operating system) cursor.
  • For example the default is cursor(ARROW), but for shape intended as a button cursor(HAND) can be used.
  • There are ARROW, CROSS, HAND, MOVE, TEXT, or WAIT. The parameter can be a path to an image as well to be used a custom cursor.
  • Example of default mode rectangle shape with P5JS.
rect(0, 0, 10, 10); // The last two parameter are the width and height.
rect(0, 0, 10, 10, 10); // The last parameter is the radius of of rounded corners.
/* More specific rounded corners.
The last 4 parameters are: top - left, top - right, bottom - right, and then
bottom - left. */
rect(0, 0, 10, 10, 10, 10, 10, 10);
  • I made general function to remove letters in a string.
function removeLetters (_string, _rmString, _all) {
  if (_all === undefined) _all = true;

  if (_all) return _string.split(_rmString).join("");
  else return _string.replace(_rmString, "");
}
  • If _all is true then delete all occurrences of _rmString in _string.
  • For example "asdasd".split("a").join("") will return "sdsd".
  • If _all is false then delete one (the first) occurrences of _rmString in _string.
  • For example "asdasd".replace("a", "") will return "sdasd".
  • So this is actually more flexible than Python's str.replace().
  • These are codes to remove n amount of letter from the end of string.
var str = "123asd";
str = str.substring(0, str.length - 3);
  • The codes above will return "123".
  • The - 3 can be adjusted to as to how many letter will be deleted from the end of string.
  • In P5JS there is textWidth() to get the width of a text in pixels. The current configurations (font, size, ...) will be used as for the calculation. So, it is the best to have this inside a class or right after the text rendered into HTML5 <canvas>.
  • Here is the reference for textWidth(), https://p5js.org/reference/#/p5/textWidth.
  • Here are some example of dictionary usage in JavaScript.
var exmplDict = { text1:"hello", text2:"world" };