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

132
Views
Javascript Arrays filter by type

i just start learn javascript and to test some array code, i end make this, there is a better away to make a filter by type of value. (Sorry any mistake english is not my mother language).

var list = ["lorem1",  "lorem2", "lorem3" , "lorem4", 1 ,2 ,3]
var number = 1
var type = typeof number
var numbers = list.filter(item => typeof item === type)
var words = list.filter(item => typeof item != type)
// Filter by value types
console.log(numbers)
console.log(words)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can write a function and pass the type as argument like so:

var list = ["lorem1",  "lorem2", "lorem3" , "lorem4", 1 ,2 ,3]

function filterByType(arr, type){
  return arr.filter(item=> typeof item === type)
}

const words = filterByType(list, 'string')
const numbers = filterByType(list, 'number')

console.log({words, numbers})

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!