Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Returns 'Undefined'

How come during the "draw" each Point returns "undefined" instead of a coordinate? Is it not possible to fill an array during setup?

let a = [];
var scl = 10;

class Point {
  constructor(i, j) {
    this.x = i;
    this.y = j;
  }
}

function setup() {
  createCanvas(600, 600);
  for(x = 0; x < width; x += scl) {
    a[x] = [];
    for(y = 0; y < height; y += scl) {
      let p = new Point(x, y);
      a[x][y] = p;
    }
  }
}

function draw() {
  background(0);
  
  a.forEach( p => {
    rect(p.x, p.y, scl);
  });
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

a is a 2-dimensional array, you need nested loops:

function draw() {
    background(0);
    a.forEach(row => row.forEach(p => rect(p.x, p.y, scl)));
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!