jeudi 18 novembre 2021

Can I write arrow function with if on a single line

For example, I have an array:

arr= ['notebook', 2, 'pens', 'bags', newElement]

I want to find and return the index of 'pens' in the array, how can I write something like:

let found = arr.find(item => arr.indexOf(item) if item =='pens')

Aucun commentaire:

Enregistrer un commentaire