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

93
Views
return all array if at least one element match

using the following array of arrays I need to do a search for an element, if it finds that element it should return the entire array it belongs to

example

const data= [[
      "car",
      "plane",
      "boat"
  ],
  [
      "paris",
      "barcelona",
      "los angeles"
  ],
  [
      "milk",
      "eggs",
      "brea",
  ]
]

if match car must return

[plane, boat]

if match paris must return

[barcelona, los angeles]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Find/Filter will return the array(s)

const data= [
  [ "car",   "plane",     "boat" ],
  [ "paris", "barcelona", "los angeles"],
  [ "milk",  "eggs",      "bread" ]
]
const findArr = (nestedArr, item) => nestedArr
  .find(arr => arr.includes(item))

const findAndExcludeItem = (nestedArr, item) => {
  const arrContaining = nestedArr.find(arr => arr.includes(item)) || []; // in case not found
  return arrContaining.filter(filteredItem => filteredItem != item);
};

const excludeArr = (nestedArr, item) => nestedArr
  .filter(arr => !arr.includes(item))



console.log(findArr(data,"paris"))
console.log(findAndExcludeItem(data,"paris"))
console.log(excludeArr(data,"paris"))

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!