Categories JavaScript Answers How to get the last item in an array with JavaScript? Post author By John Au-Yeung Post date September 14, 2022 No Comments on How to get the last item in an array with JavaScript? Spread the love To get the last item in an array with JavaScript, we use the at method. For instance, we write if (locArray.at(-1) === "index.html") { // ... } else { // ... } to get the last item from the locArray array with locArray.at(-1). Related Posts Append Item to a JavaScript ArrayAppending an item to an array in JavaScript is easy. There're 2 ways to do… How to remove a specific item from an array with JavaScript?To remove a specific item from an array with JavaScript, we call the array splice… How to move item in array to last position with JavaScript?Sometimes, we want to move item in array to last position with JavaScript. In this… By John Au-Yeung Web developer specializing in React, Vue, and front end development. View Archive → ← How to merge two arrays in JavaScript and de-duplicate items? → How to remove empty elements from an array in JavaScript? Leave a Reply Cancel replyYour email address will not be published. Required fields are marked *Comment * Name * Email * Website Save my name, email, and website in this browser for the next time I comment. Current ye@r * Leave this field empty