I know this is a pretty short question, but I was just wondering if we can short this:
cn.link.split('/')[cn.link.split('/').length - 1]
To this:
cn.link.split('/')[this.length - 1] or something like this where this can be replaced by something to make this work.
cn.link.split('/')[this.length - 1]
this
NOTE:- cn is an object.
cn
Use Array.pop() To get the last item of an array:
Array.pop()
const link = 'a/b/c/d/e' const last = link.split('/').pop() console.log(last) const url = `assets/images/products/${link.split('/').pop()}/pro_1.jpg` console.log(url)
2.1m questions
2.1m answers
60 comments
57.0k users