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

154
Views
How to remove certain elements from the inner array in JavaScripts

var array = [[10, 20, 30, 20, 50], [40, 50, 60, 20, 20], [70, 80, 90, 20, 20], [70, 80, 90, 20, 20]];

For example i want to delete elements == 50

I want this result -> array= [[10,30,20], [40,60,20], [70,90,20], [70,90,20]];

I try this solution but it is not working ->

  for (var i = 0; i < array.length; i++) {
    for (var j = 0; j < array[i].length; j++) {
      if (array[i][j] == 50) {
        array[i].splice(j, 1);
      }
    }
 }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to collect unwanted indices first and then return.

const
    data = [
        [10, 20, 30, 20, 50], 
        [40, 50, 60, 20, 20], 
        [70, 80, 90, 20, 20], 
        [70, 80, 90, 20, 20]
    ],
    //       ^^          ^^ cols with 50
    //
    indices = data.reduce(
        (r, a) => a.map((v, i) => v === 50 ? false : r[i] ?? true),
        []
    ),
    result = data.map(a => a.filter((_, i) => indices[i]));

result.forEach(a => console.log(...a));

about 4 years ago · Juan Pablo Isaza Report

0

const array = [[10, 20, 30, 20, 50], [40, 50, 60, 20, 20], [70, 80, 90, 20, 20], [70, 80, 90, 20, 20]];


const filteredArr = array.map(item => [...new Set(item.filter(i => i !== 50))])

// filterdArr = [[10, 30, 20], [40, 60, 20], [70, 80, 90, 20], [70, 80, 90, 20]];
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!