Skip to content

Instantly share code, notes, and snippets.

@narutaro
Last active September 21, 2019 08:14
Show Gist options
  • Save narutaro/a2d31ea455b2a40117bed13fb07acc1d to your computer and use it in GitHub Desktop.
Save narutaro/a2d31ea455b2a40117bed13fb07acc1d to your computer and use it in GitHub Desktop.
Filter an array based on odd or even
let ary = [
'0:00',
'0:30',
'1:00',
'1:30',
'2:00',
'2:30',
'3:00',
'3:30',
'4:00',
'4:30',
'5:00',
'5:30',
'6:00',
'6:30',
'7:00',
'7:30',
]
let onlyOdd = ary.filter((time, idx) => idx % 2 != 0 )
let onlyEven = ary.filter((time, idx) => idx % 2 == 0 )
console.log('Odd', onlyOdd)
console.log('Even', onlyEven)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment