I want to declare variables inline ,and use it in same line. like:
(var arr = ['1', '2']).forEach(a => alert(arr))
But it give me error(Unexpected token 'var'
). so is it possible in js?
EDIT: it's just an example. my real usecase is this:
var arr = [{id: 1, tags: [1, 2]}, {id: 2, tags: [5,6]}]
(var f = arr.find(item => item.id == 1)).tags.map(t => t + f.id)
I want to avoid separate declaration because i'm creating a chaining library so that every thing should be chained together in 1 line (in a clean way however)