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

115
Views
I need to check if first number of array equals to the last

I have an array

    const array = [[1, 2], [3, 3]]; arr.forEach(el => {  
      if (el[0] === el[1]) {return true}
    })
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

There is no point in return true in a forEach

I assume you mean this:

const testArr = arr => arr[0] === arr[arr.length-1]; // test first and last

const array = [[1, 2], [3, 3]]; 

const testResults = array.map(el => testArr(el)); // map the results
console.log(testResults)

// filter: 

const same = array.filter(el => testArr(el)); // FIND the array that has same first and last 

console.log(same.flat())

about 4 years ago · Juan Pablo Isaza Report

0

You should should every function

const arr = [[1, 2], [3, 3]]; 
const b = arr.every(el => el[0] === el[1]);
console.log(b); // false
about 4 years ago · Juan Pablo Isaza Report

0

This should get the desired result. Just change console.log(true) to whatever you would like to do if they equal each other. This will work on any length of array.

const array = [
  [1, 2],
  [3, 3],
];

array.forEach((el) => {
  if (el[0] === el[el.length - 1]) {
    console.log(true);
  }
});
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!