<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Последний элемент массива js]]></title><description><![CDATA[<p dir="auto">В JS самый популярный способ получить последний элемент массива - через индекс или современный метод <code>at(-1)</code></p>
<p dir="auto">Классический способ:</p>
<pre><code class="language-js">const array = [1, 2, 3, 4, 5];
const lastElement = array[array.length - 1];
console.log(lastElement); // выведет 5
</code></pre>
<p dir="auto">Новый способ:</p>
<pre><code class="language-js">const array = [1, 2, 3, 4, 5];
const lastElement = array.at(-1);
console.log(lastElement); // выведет 5
</code></pre>
<p dir="auto">Есть и дополнительные способы, к примеру через <code>slice()</code>:</p>
<pre><code class="language-js">const lastElement = array.slice(-1);
console.log(lastElement); // 5
</code></pre>
<p dir="auto"><code>pop()</code> — удаляет последний элемент из массива:</p>
<pre><code class="language-js">const lastElement = array.pop();
console.log(lastElement); // 5
// array выведет теперь [1, 2, 3, 4]
</code></pre>
<p dir="auto">Все пример работают, но лучше всего использовать новый и удобный метод <code>array.at(-1)</code>, или классику <code>array[array.length - 1]</code></p>
]]></description><link>https://forum.exlends.ru/topic/243/poslednij-element-massiva-js</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 05:49:55 GMT</lastBuildDate><atom:link href="https://forum.exlends.ru/topic/243.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 10 Sep 2025 13:56:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Последний элемент массива js on Thu, 02 Oct 2025 08:46:16 GMT]]></title><description><![CDATA[<p dir="auto">@Jspi</p>
<p dir="auto">Тут разница то в скобках и чуть меньше букав</p>
<pre><code>const lastElement = array[array.length - 1];
const lastElement = array.at(-1);
</code></pre>
]]></description><link>https://forum.exlends.ru/post/805</link><guid isPermaLink="true">https://forum.exlends.ru/post/805</guid><dc:creator><![CDATA[kirilljsx]]></dc:creator><pubDate>Thu, 02 Oct 2025 08:46:16 GMT</pubDate></item><item><title><![CDATA[Reply to Последний элемент массива js on Thu, 02 Oct 2025 08:35:53 GMT]]></title><description><![CDATA[<p dir="auto">@Jspi возможно просто привычка. Новым способом делал, но “что-то пошло не так”, а так как нужно было оперативно, вернулся к классике</p>
]]></description><link>https://forum.exlends.ru/post/800</link><guid isPermaLink="true">https://forum.exlends.ru/post/800</guid><dc:creator><![CDATA[Gleb_Osin]]></dc:creator><pubDate>Thu, 02 Oct 2025 08:35:53 GMT</pubDate></item><item><title><![CDATA[Reply to Последний элемент массива js on Mon, 06 Oct 2025 09:46:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gleb_osin" aria-label="Profile: Gleb_Osin">@<bdi>Gleb_Osin</bdi></a> очень странно, а чем новый метод не устроил, зачем писать много кода когда можно писать меньше?</p>
]]></description><link>https://forum.exlends.ru/post/745</link><guid isPermaLink="true">https://forum.exlends.ru/post/745</guid><dc:creator><![CDATA[Aladdin]]></dc:creator><pubDate>Mon, 06 Oct 2025 09:46:36 GMT</pubDate></item><item><title><![CDATA[Reply to Последний элемент массива js on Sat, 20 Sep 2025 05:20:24 GMT]]></title><description><![CDATA[<p dir="auto">Я пользуюсь классическим способом. Однажды делал новым способом, но что-то не сработался, как говорится))) Так и остановился на классике.</p>
]]></description><link>https://forum.exlends.ru/post/740</link><guid isPermaLink="true">https://forum.exlends.ru/post/740</guid><dc:creator><![CDATA[Gleb_Osin]]></dc:creator><pubDate>Sat, 20 Sep 2025 05:20:24 GMT</pubDate></item></channel></rss>